• 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!

Check when a sprite's animation completes?

LanceCS

Member
So in a platformer game I'm working on, I have a spring object that when the player touches it, it launches them in the air. I want the sprite index to change to a bouncing animation of the spring when the player hits it, and then return to normal after the animation ends. Is there anyway to check for when a sprite index animation ends? Thanks in advance.
 

Slade

Member
Indeed that would be the Animation End event.

Additionally, I would recommend having an if statement at the very start of your code so that your code only runs when your object is on a specific animation - in your case the bounce animation.

It would look something like this on the Animation End event:

GML:
if (sprite_index = spr_bounce)

{

sprite_index = spr_normal;

}
This way you can still have your object change to multiple different animations without it automatically changing back to normal after the animation ends.
 

Slyddar

Member
I didn't even think about that!
You can also have a switch statement in the animation end event, which would cater for any number of current sprite_index's ending when you require.
GML:
switch sprite_index {
  case spr_bounce:
    sprite_index = spr_normal;
  break;
}
 
Top