TLama

Untitled

Dec 10th, 2013
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.72 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ExtCtrls, PngImage;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Timer1: TTimer;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure FormDestroy(Sender: TObject);
  14.     procedure FormPaint(Sender: TObject);
  15.     procedure Timer1Timer(Sender: TObject);
  16.   private
  17.     FFrameIndex: Integer;
  18.     FFrames: array[0..29] of TPngImage;
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.dfm}
  29.  
  30. procedure TForm1.FormCreate(Sender: TObject);
  31. var
  32.   I: Integer;
  33. begin
  34.   FFrameIndex := 0;
  35.   // create all the frame objects and load the source images from files
  36.   for I := 0 to High(FFrames) do
  37.   begin
  38.     FFrames[I] := TPngImage.Create;
  39.     // source images are expected to be stored in the c:\SomeFolder\ path and needs to be
  40.     // numbered from Image0.png to Image29.png
  41.     FFrames[I].LoadFromFile(Format('c:\SomeFolder\Image%d.png', [I]));
  42.   end;
  43. end;
  44.  
  45. procedure TForm1.FormDestroy(Sender: TObject);
  46. var
  47.   I: Integer;
  48. begin
  49.   // free all the frame objects
  50.   for I := 0 to High(FFrames) do
  51.     FFrames[I].Free;
  52. end;
  53.  
  54. procedure TForm1.FormPaint(Sender: TObject);
  55. begin
  56.   // whenever the form is painted, draw the frame by the current index (that's the number,
  57.   // which is being increased with each timer tick)
  58.   Canvas.Draw(0, 0, FFrames[FFrameIndex]);
  59. end;
  60.  
  61. procedure TForm1.Timer1Timer(Sender: TObject);
  62. begin
  63.   // increase the current index until the last possible index and then start from 0
  64.   FFrameIndex := (FFrameIndex + 1) mod Length(FFrames);
  65.   // ask the system to repaint the form, which in turn fires the OnPaint event
  66.   Invalidate;
  67. end;
  68.  
  69. end.
Advertisement
Add Comment
Please, Sign In to add comment