1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 Animation Change

Discussion in 'Programming' started by GhostToast, Jun 27, 2017.

  1. GhostToast

    GhostToast Guest

    Hello Everyone! I'm new to Gamemaker and I had a quick question about changing your character animation. I currently have an idle animation set to my player object but I'm stuck on how to make him switch to my running animation when he begins to move. I'm using GameMaker Studio 2. Any help is appreciated thank you!
     
  2. hogwater

    hogwater Member

    Joined:
    Jun 22, 2017
    Posts:
    635
    You could have separate sprites for each type of animation, and change the sprite itself into another. You could also just set the image index if all the animation is contained in a single sprite. Something like:

    Code:
    {
    
    if keyboard_check(vk_right=true)
    
    {
    image_speed=.5
    image_index=4
    }
    
    if image_index>8
    
    {
    image_index=4
    }
    
    }
    This would change the image index to the fourth frame in a sprite, and cycle between the fourth and eighth frames.
     
    Last edited: Jun 27, 2017
  3. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,221
    Make sure to use proper syntax, it may not matter with gml, but if the person ever switches languages, they might have a problem.
    Code:
    if (keyboard_check(vk_right))
    {
      image_speed = .5;
      image_index = 4;
    }
    
    if (image_index > 8)
    {
      image_index = 4;
    }
    
    also, the code might not work very well either.

    I suggest
    Code:
    move = keyboard_check(vk_right) - keyboard_check(vk_left);
    if (move != 0)
    {
      sprite_index = spr_player_move;
      image_xscale = move; // flips the sprite when moving the other way
    }
    else
    {
      sprite_index = spr_player_idle;
    }
    
     
  4. GhostToast

    GhostToast Guest

    Thank you so much, everyone!! it works swimmingly
     
  5. Yazmin Mckean

    Yazmin Mckean Member

    Joined:
    Oct 22, 2018
    Posts:
    1
    I think im having a similiar problem but code makes no sense to me, can I get a super dumbed down version of what you're talking about?

    Right now when i move my player sprite its only giving me the animation for when hes walking down, how do I change it so that when I press "D", I see the walking right animation?
     

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