Walk animation start with unwanted slide impression

Hello, everyone! I just started learning GML and, while I had some satisfactory results on one side, I fail in some very simple operations. :/
I'm moving a character by pressing keys, making it go through it's sprite animation's frames but here's the problem: The character moves before taking the first step, giving the impression of sliding on the ground. Like this, If I tap quickly a movement key, the character can move around the room without a single change of it's animation's frame.
I want the character to take the step exactly when it start moving.
I tried elaborating a way by myself but I failed miserably. Forgive my ignorance!

Hope I've been clear enough!
 
Let me try to explain again first. Everything works fine. The only thing I'd like to change is the animation to show the character taking a step (second frame) immediatly when I press a movement button and cycle the animation from that point. Because right now the second frame appear after the character already traveled too much distance. Thanks for the patience!

In Create Event:

image_speed = 1.5;
spd = 1.2;
direction_facing = dir.right;

enum player {
move
}

enum dir {
right,
up,
left,
down
}

sprite_direction [player.move, dir.right] = spHeroWalkRight;
sprite_direction [player.move, dir.up] = spHeroWalkUp;
sprite_direction [player.move, dir.left] = spHeroWalkLeft;
sprite_direction [player.move, dir.down] = spHeroWalkDown;

x_frame = 0

In Step Event:

input_left = keyboard_check(vk_left);
input_right = keyboard_check(vk_right);
input_up = keyboard_check(vk_up);
input_down = keyboard_check(vk_down);

image_speed = 1.5;

moveX = 0;
moveY = 0;

moveX = (input_right - input_left) * spd;
moveY = (input_down - input_up) * spd;

//Sprite set
if (moveX < 0) direction_facing = dir.left;
else if (moveX > 0) direction_facing = dir.right;
else if (moveY < 0) direction_facing = dir.up;
else if (moveY > 0) direction_facing = dir.down;
else {
image_speed = 0;
image_index = 0;
}

sprite_index = sprite_direction [player.move, direction_facing];

//Collision
if(moveX != 0){
if(place_meeting(x+moveX, y, obj_collision)){
repeat(abs(moveX)){
if(!place_meeting(x+sign(moveX), y, obj_collision)){ x += sign(moveX); }
else { break; }
}
moveX = 0;
}
}
if(moveY != 0){
if(place_meeting(x, y+moveY, obj_collision)){
repeat(abs(moveY)){
if(!place_meeting(x, y+sign(moveY), obj_collision)){ y += sign(moveY); }
else { break; }
}
moveY = 0;
}
}

x += moveX;
y += moveY;
 
Thank you for the answer! Considering the character moving speed and the animation, image_speed have to be 1.5. Also, at 1 or less the sliding impression is even worse. :/
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Have a PRESSED check event for the keyboard and in that, do image_index++. That will ensure that every single press of the keyboard will advance the image index by one frame before continuing with the animation...
 
That's exactly what I was searching for! Thank you! Now I have to figure out a way to make it happens just one time when start moving, or it will mess up the animation if I press a direction key while the sprite is already animating. Any suggestion?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Check the image_speed value? If it's greater than 0 then the sprite is already moving... or create a new instance variable yourself to control it? Like "moving" and set it to true/false when required...
 
I already thought of these solutions but my ignorance impeded me to use them. Checking image_speed seems like it can't work in this situation, but an instance variable for player's movement did the work! Thank you very much for your patience!
 
Top