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

Another Animation End Event

T2008

Member
For some reason, I often run into problems with the Animation Event not trigger and my animations not playing properly. I've come up with this code to avoid the animation event entirely and it worked in the limited way I tried it. Does anyone see any issues with the below code in Step Event.

It took me awhile when I first started using GM that the image index runs at greater or less than whole numbers (ie 1.3, etc). Are there any other tricks or pitfalls to know about the animation end event? I find this and the alarms some of the most unreliable parts to GM and it's probably because I don't know exactly how to use them right.

Code:
//Set Sprite Index
        if (!talking) {
            sprite_index = spr_zombie1_idle_w;
            image_speed = 1;
        }
        if (talking) {
            image_index = 0;
            image_speed = 1;
            sprite_index = spr_zombie1_scream_w;
            if (image_index >= 4) { //last image of sprite  
                image_speed = 0;
            }
        }
 

angelwire

Member
It seems the more I use Gamemaker the less I like using the built-in events and variables. Animation End, image_speed, image_index etc... are all great until you need extra control over how they work.

I'm not sure exactly what you're trying to do. But maybe this will help:
GML:
///Step
//Freeze just before animation end event
if (image_index + image_speed >= sprite_get_number(sprite_index)-math_get_epsilon())
{
    image_speed = 0;
    image_index = sprite_get_number(sprite_index)-math_get_epsilon();
}
Using math_get_epsilon() puts the image_index as close to the Animation End without actually triggering the Animation End event.

You should probably replace if (talking) with if (talking and sprite_index == spr_zombie1_idle_w) so that the image_index is only reset to 0 when the object is changing sprites.

Hopefully that helps. If not, could you describe what you're trying to accomplish and what's actually happening?
 
Last edited:
I find this and the alarms some of the most unreliable parts to GM and it's probably because I don't know exactly how to use them right.
Whaaaaaa :oops:?!
Bro, you're the first person I ever heard say alarms are unreliables, this is total nonsense. I use them all the time, for all sorts of things, and not once that I can remember it failed to do it's job.
And for the animation End, it triggers when your animations has finished all it's frames, as the name implies. You don't need to round image indexes or stuff like that, or get the OS float precision every step (you can do it once, if you dont change it).
 

samspade

Member
I've also never had any issues with the built in alarms or animation end event. Sometimes I don't use them because I want additional control, e.g. I want something to happen as part of a state at a specific point in the code rather than when the animation event fires, but they work as described. In 2.3.1 we also have sprite messages now which can work in some cases:

 
I've also never had any issues with the built in alarms or animation end event. Sometimes I don't use them because I want additional control, e.g. I want something to happen as part of a state at a specific point in the code rather than when the animation event fires, but they work as described. In 2.3.1 we also have sprite messages now which can work in some cases:

I can see this feature being SUPER useful in fight games, and anything that needs to trigger a col_box on a certain frame.
Still waiting after the jam is done to strat messing with the beta, tho, but this is exciting!
 

T2008

Member
Thanks for all of the responses! I've been away from my computer so haven't had a chance to to look into all of the suggestions. I will definitely try them.

Re: animation end event, it seems to me that it will not trigger if the animation speed skips the last frame. This has happened to me a lot. One time, when I switched image speed to .9, it then worked how I wanted it to. I probably don't have a full understanding of it or the alarms which is why they aren't reliable for me. If I create my own clock, however, it always works how I want it to.
 
Top