GMS 2 Animation Change

G

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!
 

hogwater

Member
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:

Simon Gust

Member
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.
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;
}
 
Y

Yazmin Mckean

Guest
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?
 
Top