[SOLVED]Non looping states/animations

Schwee

Member
Hey all,

My game is featuring a character (and enemies) that will have states/animations that only play a single time before returning to another state. Examples would include landing animations, sliding animations, etc. My current code is full of hacks. I know that the image_index is a float, not an int. So my code has stuff like the following:

if(image_index > 6.75) { isSliding = false; }

Edit: Just wanted to clarify that I'd use this knowing my image_speed is, let's say, .2. Aka I will definitely hit a value between 6.75 and 7.

This is a made up example but it's not too far off from what I am actually doing. I notice that this method always cuts the last frame off slightly sooner than usual. How do you guys handle your events like this? I am aware that the Animation End event exists but I don't see much documentation on it, and I'd personally rather keep this logic within my Step event (or a script of sorts) if possible.

Thanks.
 
To nicely handle this in the step event, you'll want to do something like this:

Code:
var anim_end = false;

if ((image_index + image_speed) >= sprite_get_number(sprite_index))
{
    anim_end = true;
}
... You just need to make sure this happens before image_speed is actually added to image_index, as I'm fairly certain Studio will wrap the value as soon as it's set. You can do the same thing with a negative image_speed value, but instead check if the result is below 0.
 

Schwee

Member
That...doesn't sound too shabby. I'm slightly embarrassed I didn't think of that. When exactly does the image_speed get added to the image_index?
 
I'm not entirely sure, to be honest. My guess is either between "Step" and "End Step", or between the sometime after all the Step Events but before some kind of Draw Event. Either way, it should be fine to use in the normal Step Event.
 

TheouAegis

Member
Or use a timer variable. Change the sprite_index and image_speed, then set the timer to image_number/image_speed. Tick the timer down and when it hits 0 goto the next state.
 
Top