I want to make a sprite in game maker that contains 5 sub images to stop when it reaches the last one how can I do this using code?
Asked
Active
Viewed 2.4k times
2 Answers
8
In Animation End
event:
image_speed = 0;
image_index = image_number - 1;

Dmi7ry
- 1,777
- 1
- 13
- 25
-
When I use this code, the animation doesn't even start – shrouk Apr 16 '16 at 12:16
-
1This code stops animation after animation played once. See [example](https://dl.dropboxusercontent.com/u/78963719/stackoverflow/gml/animation_one_time.gmz) – Dmi7ry Apr 16 '16 at 16:29
-
You have to put it in the Animation End event...I'm assuming you put it in step – sam1370 May 28 '18 at 00:48
1
Run this in the Step even of your object:
If image_index == 4 Then image_speed = 0;
image_index
is the index of the current frame in the object's sprite's animation, image_speed
is the speed of the animation (in frames per step). This code just checks if the animation is at the final frame (the frames are 0-indexed, so the 5th frame is index 4.), and if so sets the speed to 0
.

PGmath
- 381
- 3
- 16
-
it gives me this error: Unable to find any instance for object index '12' name 'obj_arrow_move_one_direction' at gml_Object_obj_magnet_StepNormalEvent_3 (line 13) - if(obj_arrow_move_one_direction.image_index==4) – shrouk Apr 13 '16 at 02:07