• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Gamemaker 1.4 Top down movement

R

Ryscale

Guest
So currently I'm working on a top down game, but the sprite animations only consists of left and right (like crypt of the necrodancer) I've been trying to get the up and down animation done depending on the last direction the player was facing. Here is my step event code so far. For some reason the animation for up and down are the idle animation. Could anyone help me on this?

/// Tile Movement x = left and right /// y = up and down
/// +4 movement

var right_key = keyboard_check(ord("D"))
var left_key = keyboard_check(ord("A"))
var down_key = keyboard_check(ord("S"))
var up_key = keyboard_check(ord("W"))
var idle = keyboard_check(vk_nokey)

/// Move Right
if (right_key)=true and place_meeting(x+spd,y,o_col)=false {
x=x+spd
sprite_index = MC_move_R;
image_speed = ispd;
last_direction = 1;
}

/// Move Left
if (left_key)=true and place_meeting(x-spd,y,o_col)=false {
x=x-spd
sprite_index = MC_move_L;
image_speed = ispd;
last_direction = -1;
}

/// Move Down
if (down_key)=true and place_meeting(x,y+spd,o_col)=false {
y=y+spd
image_speed = ispd;
}

/// Move Up
if (up_key)=true and place_meeting(x,y-spd,o_col)=false {
y=y-spd
image_speed = ispd;
}

///idle animation
if (idle) || (!right_key && !left_key) {
if (last_direction == -1) {
sprite_index = MC_idle_L;
} else {
sprite_index = MC_idle_R;
}
}

///Animation up and down
if (up_key && down_key) {
if (last_direction == -1) {
sprite_index = MC_move_L;
} else {
sprite_index = MC_move_R;
}
}
 

Simon Gust

Member
Slight logic hicup, in your Animation for up and down, you're asking your game if both the up key and the down key are pressed at the same time.
It should be, if either of the keys are pressed. if (up_key || down_key) {
 
R

Ryscale

Guest
Slight logic hicup, in your Animation for up and down, you're asking your game if both the up key and the down key are pressed at the same time.
It should be, if either of the keys are pressed. if (up_key || down_key) {
Thank you, so much! appreciated!
 
Top