G
GrandFree
Guest
So basically I have a character that moves in 8 directions (each direction has a sprite).
Let's say I'm moving in the top-left direction. I want it so when I stop moving, if the last general direction I was going in was top-left, then set the sprite to the top left sprite.
The problem is, if I don't release both the up and left keys in the same frame, then the character's last sprite will be set to either left or up. Aesthetically, it just feels strange when my player stops moving and he's not facing the direction that my brain knew he was facing when I released both keys. I'd like it so the last sprite is set to the last general direction I was going in for the longest period of time.
What's the best way to combat this? Should I just measure how long a certain direction was held for? Or is there a better way?
Let's say I'm moving in the top-left direction. I want it so when I stop moving, if the last general direction I was going in was top-left, then set the sprite to the top left sprite.
The problem is, if I don't release both the up and left keys in the same frame, then the character's last sprite will be set to either left or up. Aesthetically, it just feels strange when my player stops moving and he's not facing the direction that my brain knew he was facing when I released both keys. I'd like it so the last sprite is set to the last general direction I was going in for the longest period of time.
What's the best way to combat this? Should I just measure how long a certain direction was held for? Or is there a better way?
Code:
if(keyboard_check(ord("A"))) {
sprite_index = spr_move_left;
if(keyboard_check(ord("W"))) {
sprite_index = spr_move_leftup;
}
else if(keyboard_check(ord("S"))) {
sprite_index = spr_move_leftdown;
}
}
else if(keyboard_check(ord("D"))) {
sprite_index = spr_move_right;
if(keyboard_check(ord("W"))) {
sprite_index = spr_move_rightup;
}
else if(keyboard_check(ord("S"))) {
sprite_index = spr_move_rightdown;
}
}
else if(keyboard_check(ord("W"))) {
sprite_index = spr_move_up;
if(keyboard_check(ord("A"))) {
sprite_index = spr_move_leftup;
}
else if(keyboard_check(ord("D"))) {
sprite_index = spr_move_rightup;
}
}
else if(keyboard_check(ord("S"))) {
sprite_index = spr_move_down;
if(keyboard_check(ord("A"))) {
sprite_index = spr_move_leftdown;
}
else if(keyboard_check(ord("D"))) {
sprite_index = spr_move_rightdown;
}
}
Last edited by a moderator: