SOLVED Make something happen when sprite animation ends

Lunarium

Member
Hello, i'm having trouble making it so that when a sprite animation ends, something happens
GML:
if (stab = 1)
{
    sprite_index = s_clover_stab
    if (image_index > image_number - 1)
    {
        sprite_index = s_clover_idle
        stab = 0
    }
    
    
}
This is the code i made, except when i run the game the animation just runs infinitely. What am i supposed to do?
 

Slyddar

Member
The code waiting until image_index become higher than index of last image_number, which will never happen. You simply missing =
It has to be
GML:
if (image_index >= image_number - 1)
Not quite true, unless he is setting his image_index to image_number - 1 directly, and setting image_speed to 0, which he does not say.

GML:
sprite_index = s_clover_idle
stab = 0
You need to stop the animation from playing, so add these 2 lines :
GML:
sprite_index = s_clover_idle
stab = 0
image_speed = 0;
image_index = image_number - 1;
You then just set image_index = 0, and image_speed = 1, for the next sprite animation when you need it.
 
Last edited:

Lunarium

Member
Not quite true, unless he is setting his image_index to image_number - 1 directly, and setting image_speed to 0, which he does not say.





You need to stop the animation from playing, so add these 2 lines :

GML:
sprite_index = s_clover_idle

stab = 0

image_speed = 0;

image_index = image_number - 1;


You then just set image_index = 0, and image_speed = 1, for the next sprite animation when you need it.
I did what you guys said, but for some reason stab still doesn't go back to 0 and the event keeps happening. Though for some reason if i move left or right stab DOES go back to 0 and the animation stops and goes back to the idle one.
 
Last edited:

Slyddar

Member
Then you have code elsewhere effecting it. Get used to using things like this, show_debug_message("TEST1"), in places to check if code you expect to run, actually runs. When changing stab to 0 for example.
 

Lunarium

Member
Then you have code elsewhere effecting it. Get used to using things like this, show_debug_message("TEST1"), in places to check if code you expect to run, actually runs. When changing stab to 0 for example.
Yeah, i do that a lot. But yeah I'll try to see what i can find soon, Thanks for the help. I like your tutorials
 

Lunarium

Member
I solved the problem.
I ended up doing something much simpler, I deleted the old code (the one i posted here) and created another object with the other sprite (the one that needs to do something when its animation ends)
then i did this:
GML:
if (stab = 1)
{
	instance_create_layer(x,y,"Player",o_clover_stab)
	instance_destroy(o_clover)
}
}
Then in the new object, i created an Animation End event.
GML:
stab = 0
instance_destroy(o_clover_stab)
instance_create_layer(x,y,"Player",o_clover)
}
So now i guess the problem is solved.
 
Top