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