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;
}
}
/// 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;
}
}