GameMaker Run Animation 1 time.

M

Marcos Mena

Guest
Hello!

I've been kicking my head against the wall for way too long so I'm here asking for help.

This sounds pretty simple in my head but I can't seem to figure it out, I want to run an animation one time, and then go back to the original sprite.

Let me lay it out really quick:

I have spr_player_idle (3 frames) and spr_player_attacking (7 frames)

Running on obj_player I have the idle animation set, I want to make it so that when you press Shift the spr_player_attacking animation runs from the beginning to the end and then go back to spr_player_idle.

I guess that's pretty much it, I thank you in advance.
 
F

Fukle

Guest
Hey mate I'm on my mobile at work so I'll try my best to help you.

I would tackle this personally by having a step event in the character that checks;

Code:
If ((sprite_index == running sprite) && (image_index = max number of images))
{
     Sprite_index = idle sprite
}
You will have to replace the name of the sprites in that code but that should work in theory.
 

hippyman

Member
Animation end event is what you want. When you switch animations, change the image index back to zero to start at the beginning of the animation and then in the animation end event do what TrunX said.
 
M

Marcos Mena

Guest
Hey mate I'm on my mobile at work so I'll try my best to help you.

I would tackle this personally by having a step event in the character that checks;

Code:
If ((sprite_index == running sprite) && (image_index = max number of images))
{
     Sprite_index = idle sprite
}
You will have to replace the name of the sprites in that code but that should work in theory.

I can see what you mean so change the sprite of the object to the animation and as soon as the image gets to the max of images it changes to the Idle sprite.

I'll try to make that work.

Thanks a lot!
 
M

Marcos Mena

Guest
You can do it either with code or with the animation end event where you can ask if its the attack animation that ended and switch back to idle in that case..
I gotcha, I'd say it would be much more efficient to do it with code. Wouldn't want to deal with more than 3 or 4 events, besides create and step.
 
F

Fukle

Guest
N
I can see what you mean so change the sprite of the object to the animation and as soon as the image gets to the max of images it changes to the Idle sprite.

I'll try to make that work.

Thanks a lot!
No worries at all. Let me know how you go mate.
 
M

Marcos Mena

Guest
N

No worries at all. Let me know how you go mate.
I would like to use your way cause I don't really understand how the End Animation event works, I'm doing the following:

I have an enemy = obj_enemy and when I'm trying to kill it but running the dead animation first = spr_enemy_dead

so the code goes like this:

sprite_index = spr_enemy_dead
if (obj_player.y < y-32)
{
sprite_index = spr_enemy_dead
if ((sprite_index == spr_enemy_dead) && (image_index == 3))
{
instance_destroy();
}
}

Is not working, it's just repeating the animation over and over

any ideas?
 
Top