• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Stop an animation

Newzak

Member
I am a begginer in game maker studio (I start 2 weeks ago) and I want to know how to stop an animation of a sprite at a certain frame (frame 200) and once time it is at the frame 200, I want to change the room

Can you help me please ?
 

samspade

Member
Here are two options.

Option 1: use code like this in your step event:

GML:
//somewhere in the step event
if (image_index > 200) && (prev_image_index <= 200) {
    room_goto(new_room)
}
prev_image_index = image_index;
prev_image_index would need to be initialized in the create event as well. The idea here is that you are checking to see what the current frame is and what the frame was last step and if the current frame is above 200 but last step it was equal to or less than 200 then you know that it just crossed that threshold.

Option 2: use broadcast message. I have a tutorial on how to do so. If you're just starting, they are a little complicated and might appear to take a little more code to set up than the above, but once you understand them, they are good solution to this type of problem and far more flexible (in my opinion)

 
Well, if it's the last frame of the sprite, you can just use the Animation End event, it automatically fires up at the end of every 'loop' of animation.
Just tell the program to switch room there.
 

samspade

Member
Well, if it's the last frame of the sprite, you can just use the Animation End event, it automatically fires up at the end of every 'loop' of animation.
Just tell the program to switch room there.
That's a good point. And in this case, unless the object is persistent, you can just make it the last frame of the sprite since you are going to another room.
 
Top