1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Animation playing only first frame

Discussion in 'Programming' started by MooMoo, Jan 29, 2017.

  1. MooMoo

    MooMoo Guest

    I am trying to get my character to play the animation spr_player_knife_attack but when I activate it with J it plays the first frame and then resets.

    image_index = 0
    sprite_index = spr_player_knife_attack
    if (image_index = 13)
    {
    sprite_index = spr_player_knife_idle
    }

    That is the code I wrote can someone help me fix this?
     
  2. barshems

    barshems Member

    Joined:
    Oct 7, 2016
    Posts:
    78
    looks like you might have image_index = 0; which would make it reset every time it plays through your code.

    i'm just learning myself. I think if you remove the image_index = 0 it should solve the problem

    OR

    move image_index = 0; to inside your if statement

    sprite_index = spr_player_knife_attack
    if (image_index = 13)
    {
    image_index = 0
    sprite_index = spr_player_knife_idle
    }

    I think if your image_speed is set to higher than 0 the index should automatically change on it's own.

    I don't know though im' still pretty bad at this might want to get a second opinion but I hope it helps
     
    MooMoo likes this.
  3. CoderJoe

    CoderJoe Member

    Joined:
    Jun 22, 2016
    Posts:
    166
    @barshems is right. the image_index = 0 will reset everytime you press the key. What you probably want is to reset the image_index once. To do this you can just check if the sprite_index = spr_player_knife_attack. if its false then reset the image_index and change the sprite_index to your attack animation. You can also use animation end event to change back into your idle animation.
     
    MooMoo likes this.
  4. MooMoo

    MooMoo Guest

    thanks but I have a few questions to what you mean (I am new to game maker)
    this is what it looks like now

    if(!sprite_index = spr_player_knife_attack)
    {
    image_index = 0
    }
    sprite_index = spr_player_knife_attack

    and now nothing happens when I push the button
    also I do not see a clear way to use animation end event to switch back
    do you mean make the animation end event include
    sprite_index = spr_player_knife_idle
    if so then I am over thinking this
     
  5. Diveyoc

    Diveyoc Guest

    I think you need something like this in the code for when the J key is pressed.
    Make sure your using keyboard_check_pressed and not just keyboard check.

    sprite_index = spr_player_knife_attack;
    if image_index >=13
    sprite_index = spr_player_knife_idle;
     
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,434
    When you press the J key, set the new Sprite to your attacking Sprite and set the image speed to however fast you want your attacking Sprite to animate and set the image_index to 0 at that point.

    Then use an animation end event to check if the Sprite is your attack Sprite, and if it is change back to your idle Sprite and set the image speed to whatever your idle Sprites animation speed should be.
     
  7. MooMoo

    MooMoo Guest

    Thanks for the help guys but I still have the problem of the animation never starting when I press J
     

Share This Page