GML Change sprite in movement situations

W

weslley

Guest
Good night, i have a problem with a platform game, i can't find the solution.
My player have different side, left and right, then the image_xcale don't work to me. How i change the sprite to stand to left, stand to right, run to left, run to right, jump to left and jump to right?
the initial code:


/// @description movement
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
move = key_right + key_left;
hsp = move * moveSpeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -speedJump
}


//colision H
if (place_meeting(x+hsp,y,obj_wall))
{
while (!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//colision V
if (place_meeting(x,y+vsp,obj_wall))
{
while (!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0
}
y += vsp;

// animation

if (!place_meeting(x,y+1,obj_wall))
{
sprite_index = spr_jumpRight
if (sign(vsp) > 0 ) image_index = 1 else image_index = 0;
}
else
{

if (hsp > 0)
{
sprite_index = Spr_playerright
}
else if (hsp < 0)
sprite_index = spr_Playerleft
}
 

Bayesian

Member
Set up a facing variable(1=right/-1=left) and use that in some if statements that check the players speed and whether they are off the ground to base what sprite to show.
 
W

weslley

Guest
Set up a facing variable(1=right/-1=left) and use that in some if statements that check the players speed and whether they are off the ground to base what sprite to show.
you can give me a example?
 
W

weslley

Guest
Set up a facing variable(1=right/-1=left) and use that in some if statements that check the players speed and whether they are off the ground to base what sprite to show.
I got it, I use de code:

if keyboard_check_released (vk_right)
{
direction = 1;
}
if keyboard_check_released (vk_left)
{
direction = -1;
}

Thank you, my friend, you helped me a lot.
 
Top