Legacy GM Switching between Idle and Walking

R

RozeJacklyn69

Guest
Hello! I just joined and beggining to program my first game in GM!
I'm a total noob soo...
I need some help on switching between Idle and Walking animations for my player.

I have seperate animations for when my character is walking up, down, left and right, and same goes for idle.
I have separate codes for when the walking is supposed to take place (i.e when the player presses W, A, S or D)
(Something like this v)

MySpeed = 1.8

if keyboard_check(ord('S')) {

y = y + MySpeed
sprite_index = splayer_walking_down
image_speed = .5
}

And I'm having trouble switiching to when the player is supposed to be idle

Can someone help?
 

Mick

Member
You could do something like this:

Code:
if keyboard_check(ord('W')) {
  // W
}
else if keyboard_check(ord('A')) {
  // A
}
else if keyboard_check(ord('S')) {
  // S
}
else if keyboard_check(ord('D')) {
  // D
}
else {
  // Idle
}
 

TheouAegis

Member
Set a facing variable. Set it to 0 when walking right, 1 when walking up, 2 when walking left, 3 when walking down. Create an array in the create event to specify which sprites to use.

walk_array[0] = spr_walk_right
walk_array[1] = spr_walk_up
walk_array[2] = spr_walk_left
walk_array[3] = spr_walk_down
idle_array[0] = spr_idle_right
idle_array[1] = spr_idle_up
idle_array[2] = spr_idle_left
idle_array[3] = spr_idle_bottom

When you are walking, set the sprite to walk_array[facing]. When you are idle, set the sprite to idle_array[facing].
 
R

RozeJacklyn69

Guest
I think I screwed up somewhere for the idle code, so here's what I have

if !keyboard_check(ord('W')) {
sprite_index = idle_array[2]
image_speed = .3
}
else if !keyboard_check(ord('A')) {
sprite_index = idle_array[0]
image_speed = .3
}
else if !keyboard_check(ord('S')) {
sprite_index = idle_array[3]
image_speed = .3
}
else if !keyboard_check(ord('D')) {
sprite_index = idle_array[1]
image_speed = .3
}

I have tried this but game maker never recognised the walk animation anymore

I'm definitely sure I am not doing this right
help?
 
R

RozeJacklyn69

Guest
Thank you for the help, and I have FINALLY found a way!

if keyboard_check_released(ord('A')){
sprite_index = idle_array[0]
image_speed = .1
}

Thank you so much for helping :)
 
Top