GMS 2 Run Animation 1 time.

Discussion in 'Programming' started by Marcos Mena, Feb 6, 2017.

  1. Marcos Mena

    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.
     
  2. Fukle

    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.
     
    Marcos Mena likes this.
  3. TrunX

    TrunX Member

    Joined:
    Jun 30, 2016
    Posts:
    143
    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..
     
    Marcos Mena and hippyman like this.
  4. hippyman

    hippyman Member

    Joined:
    Jun 20, 2016
    Posts:
    565
    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.
     
    Marcos Mena likes this.
  5. Marcos Mena

    Marcos Mena Guest


    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!
     
  6. Marcos Mena

    Marcos Mena Guest

    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.
     
  7. Fukle

    Fukle Guest

    N
    No worries at all. Let me know how you go mate.
     
    Marcos Mena likes this.
  8. Marcos Mena

    Marcos Mena Guest

    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?
     
  9. Marcos Mena

    Marcos Mena Guest

    NVM, I made it work. Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice