### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Animated images  (Read 3686 times)

#### goranp13

• Newbie
• Posts: 2
##### Animated images
« on: March 20, 2015, 08:56:16 pm »
Hello to all
I am a newbee, i am making application and I have put three images (Arrows), now I want to show them one after another to simulate moving arrow. Can anyone help me with this.

Thanks.

#### Mike.Cornflake

• Hero Member
• Posts: 1256
##### Re: Animated images
« Reply #1 on: March 20, 2015, 09:24:49 pm »
You can actually move the image.

Assuming you've put the arrow image in a TImage called Image1, then try the following

Put a button on the form, and add the following code to it...

Code: [Select]
`procedure TForm1.Button1Click(Sender: TObject);Begin  //Arrow1.Left := Arrow1.Left + 10;  // Use this code if you're using a TArrow instead of a TImage...  Image1.Left := Image1.Left + 10;End;`
Lazarus Trunk/FPC Trunk on Windows [7, 10]
Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

#### emil

• New Member
• Posts: 16
##### Re: Animated images
« Reply #2 on: March 20, 2015, 11:38:36 pm »
-make a image (from top - additional - TImage)
-make a timer (from top - system -timer);
-click on timer, click on interval, set it from 1000 to 50
-now change the name of the images: if you have 3 images set their nam to 1 2 and 3 (enter in the folder and change the name)
-in program var i:integer;
-click on events (from timer)
-click onTimer
-now write:
i:=i+1;
if i=3 then i :=0;

.png or .bmp

its very easy algoritm and the most useful

if you want to optimize it you can try:

make an array of pictures:
var
pic:array[1..3] of TPicture;

procedure TForm1.FormCreate(Sender: TObject);
begin
for i:=1 to 3 do  pic:=TPicture.create;

end;

now, at the "OnTimer":
inc(i);

image.picture:=pic[ i ]

if i=3 then i:=0;
« Last Edit: March 20, 2015, 11:41:06 pm by emil »

#### goranp13

• Newbie
• Posts: 2
##### Re: Animated images
« Reply #3 on: March 21, 2015, 12:13:16 am »
Thanks