I’m working on a 2D Platformer Game in GMS 2 and my player object won’t change sprites when I push the buttons that are supposed to make him change to his shooting and crouching poses. I have tried putting the different poses into different sprites, and putting the poses into different frames in the same sprite. Neither of these solutions has worked and I am kind of desperate for some help with this.
Currently the poses are in separate sprites and the code looks like this:
// Movement
key_right = keyboard_check(ord(“D”))
key_left = keyboard_check(ord(“A”))
key_jump = keyboard_check(ord(“W”))
key_crouch = keyboard_check(ord(“S”)) // This button doesn’t work
// Attacks
key_shoot = keyboard_check(vk_space) // Neither does this one
key_punch = keyboard_check(ord(“J”))
key_kick = keyboard_check(ord(“K”))
...
if (!key_left) and (!key_right) {
sprite_index = spr_player_stand
image_speed = 0
image_index = 0
} else if (key_left) and (key_right) {
sprite_index = spr_player_stand
image_speed = 0
image_index = 0
} else if (key_left) {
xscale = -0.6
sprite_index = spr_player_run
} else if (key_right) {
xscale = 0.6
sprite_index = spr_player_run
} else if (key_crouch) {
sprite_index = spr_player_crouch
} else if (key_shoot) {
sprite_index = spr_player_shoot
} else if (key_punch) {
sprite_index = spr_player_punch
} else if (key_kick) {
sprite_index = spr_player_kick
}
P.S. Please don’t bother correcting my lack of “;” at the end of the lines. I know that it is a bad habit and I know that I am doing it so don’t bother telling me to stop it.