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

Animation End Event

T2008

Member
I'm having trouble with my animation not stopping at the end of animation event though I set the say image_index = -1; The death animation just keeps playing. The relevant code is below (I omitted the hit code/hitbox/alarms - I can post if needed). Any ideas would be greatly appreciated! I'm sure it's probably something stupid I'm overlooking.

Step Event:
Code:
//Set Sprite 
//---Hit
if (!enemy_dead) && (hit) && (hp > 0) {
    sprite_index = spr_robot_melee_static_hit;    
}  
//---Not Hit
if (!enemy_dead) && (!hit) && (hp > 0) {
    sprite_index = spr_robot_melee_static;    
}
//---Dead
if (hp <= 0) {
    sprite_index = spr_robot_melee_static_die;
    enemy_dead = true;
}
if (enemy_dead) {
    if (!death_sound_played) {
        audio_play_sound(snd_enemy_die,10,false);
    }
    death_sound_played = true;
    enemy_disappear_clock -=1;
}
//Destroy If Clock Has Run
if (enemy_disappear_clock <= 0) {
    instance_destroy();    
}
Animation End Event:
Code:
//Stop Die Animation
if (sprite_index = spr_robot_melee_static_die) {  
    image_index = -1;
}
 

Mr Magnus

Viking King
Setting the image index just changes the current image displayed. The animation will then just keep going the next frame as if nothing happened.

You want image_speed = 0; which stops the animation all together.
 

T2008

Member
Thanks for responding. I forgot to mention that I already tried that and it didn't work. I also tried in step event, if enemy dead, image = speed = 0, which also didn't work.
 
You are probably setting image_speed in the Step Event as well. Thus you set it to 0 when the Animation End gets triggered, and then in the next step, it gets set back to some other value, negating the 0 it was set to in Animation End.
 

T2008

Member
Thanks for the suggestions ReferesherTowel. I actually deleted all image_speed code in step event and still it won't stop. It seems as though the animation end event is not triggering for some reason. This is very frustraing.

Edit: Well, I figured out that GM was skipping the last animation frame and therefore never triggering the Animation End Event. When I set the image speed to 1, it was an endlessly looping die animation; when I set image speed to .9, to stopped.

Does anyone know if there is a way to ensure that the last frame is always played so that this doesn't happen? It seems less than ideal to have to guess at the image speed for it to stop.
 
Last edited:

Slyddar

Member
Try using show_debug_message(image_index) in the step event, to verify what the image_index is counting up to. If you want to manually manage it, you can use these macros in the step event, and just check "if ANIMATION_END { ..."
Code:
//speed per frame
#macro FRAME_SPEED            (sprite_get_speed(sprite_index)*image_speed)/room_speed
//end of animation
#macro ANIMATION_END        image_index >= (image_number - FRAME_SPEED)
 
Top