Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, PngImage;
- type
- TForm1 = class(TForm)
- Timer1: TTimer;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- private
- FFrameIndex: Integer;
- FFrames: array[0..29] of TPngImage;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- var
- I: Integer;
- begin
- FFrameIndex := 0;
- // create all the frame objects and load the source images from files
- for I := 0 to High(FFrames) do
- begin
- FFrames[I] := TPngImage.Create;
- // source images are expected to be stored in the c:\SomeFolder\ path and needs to be
- // numbered from Image0.png to Image29.png
- FFrames[I].LoadFromFile(Format('c:\SomeFolder\Image%d.png', [I]));
- end;
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- var
- I: Integer;
- begin
- // free all the frame objects
- for I := 0 to High(FFrames) do
- FFrames[I].Free;
- end;
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- // whenever the form is painted, draw the frame by the current index (that's the number,
- // which is being increased with each timer tick)
- Canvas.Draw(0, 0, FFrames[FFrameIndex]);
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- // increase the current index until the last possible index and then start from 0
- FFrameIndex := (FFrameIndex + 1) mod Length(FFrames);
- // ask the system to repaint the form, which in turn fires the OnPaint event
- Invalidate;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment