• 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!

Sprint animation still plays when only holding shift and not a direction.

V

VanTheMan

Guest
So I have 2 separate animations for walk and sprint (I wanted the sprinting to be a little bouncier),

Point is, in my code (shown) when I hold shift AND a direction the sprint animation plays; and when I only hold the direction the walking animation plays.

But when I have been sprinting and let go of the direction without letting go of shift, the animation continues to play as if I'm moving (I'm obviously not).

How can I fix this problem? - Here's my code.


CREATE:
walk_speed = 1.5;
sprint_speed = 3;
facing = 270;
move_stop = 0;
collision_speed = walk_speed + 5.5

image_xscale = 4;
image_yscale = 4;


STEP:
//Movement Cancel
if(mouse_check_button(mb_left)){
move_stop = 1
}
else move_stop = 0

//Movement
if(keyboard_check(ord("A")) && keyboard_check(vk_shift) && move_stop != 1 && place_free(x - collision_speed,y)){
x -= sprint_speed
sprite_index = spr_player_l_run
facing = 180
}
else if(keyboard_check(ord("A")) && move_stop != 1 && place_free(x - collision_speed,y)){
x -= walk_speed
sprite_index = spr_player_l_walk
facing = 180
};
if(keyboard_check(ord("D")) && keyboard_check(vk_shift) && move_stop != 1 && place_free(x + collision_speed,y)){
x += sprint_speed
sprite_index = spr_player_r_run
facing = 0
}
else if(keyboard_check(ord("D")) && move_stop != 1 && place_free(x + collision_speed,y)){
x += walk_speed
sprite_index = spr_player_r_walk
facing = 0
};
if(keyboard_check(ord("W")) && keyboard_check(vk_shift) && move_stop != 1 && place_free(x,y - collision_speed)){
y -= sprint_speed
sprite_index = spr_player_b_run
facing = 90
}
else if(keyboard_check(ord("W")) && move_stop != 1 && place_free(x,y - collision_speed)){
y -= walk_speed
sprite_index = spr_player_b_walk
facing = 90
};
if(keyboard_check(ord("S")) && keyboard_check(vk_shift) && move_stop != 1 && place_free(x,y + collision_speed)){
y += sprint_speed
sprite_index = spr_player_f_run
facing = 270
}
else if(keyboard_check(ord("S")) && move_stop != 1 && place_free(x,y + collision_speed)){
y += walk_speed
sprite_index = spr_player_f_walk
facing = 270
};

//Idling
if(keyboard_check(vk_nokey)&&facing = 90){
sprite_index = spr_player_b_idle
};
if(keyboard_check(vk_nokey)&&facing = 180){
sprite_index = spr_player_l_idle
};
if(keyboard_check(vk_nokey)&&facing = 270){
sprite_index = spr_player_f_idle
};
if(keyboard_check(vk_nokey)&&facing = 0){
sprite_index = spr_player_r_idle
};

//Attack Animation
if(mouse_check_button(mb_left)&&facing = 90){
sprite_index = spr_player_b_attack
};
if(mouse_check_button(mb_left)&&facing = 180){
sprite_index = spr_player_l_attack
};
if(mouse_check_button(mb_left)&&facing = 270){
sprite_index = spr_player_f_attack
};
if(mouse_check_button(mb_left)&&facing = 0){
sprite_index = spr_player_r_attack
};
 

Slyddar

Member
The way you have it setup could do with some improvements. I suggest capturing the key inputs all at the top into local variables, and just referring to those throughout that step.

Besides that, in answer to your query, in order for the walk sprite to be applied the conditions you set have to be met, which they are not. Just looking at this section.
Code:
if(keyboard_check(ord("A")) && keyboard_check(vk_shift) && move_stop != 1 && place_free(x - collision_speed,y)){
x -= sprint_speed
sprite_index = spr_player_l_run
facing = 180
}
else if(keyboard_check(ord("A")) && move_stop != 1 && place_free(x - collision_speed,y)){
x -= walk_speed
sprite_index = spr_player_l_walk
facing = 180
};
The 2nd condition needs to be true, and you said you stopped pressing a direction and held shift and it didn't change to the walk. To change to walk this line needs to be true -
Code:
else if(keyboard_check(ord("A")) && move_stop != 1 && place_free(x - collision_speed,y))
and it is not, as you are not holding A.

Note you can wrap your code on the forum in [.code.] and [./code.], but without the periods, to make it easier for use to read and help you.
 
V

VanTheMan

Guest
My question was how to change to the idle animation when I let go of a direction but not shift, but thanks. The walking animation applies when I let go of shift.
 
Top