A
Agletsio
Guest
Ok so I recently did Shaun Spalding's "Platformer Basics" tutorial in an attempt to learn how to work with gravity and jumping. Everything concerning the tutorial went perfect but now I'm not sure how to approach my sprite animation.
Below you will find my current code layout in step event of Player (everything up until "///Sprite Control" is part of the tutorial.) The result of this is that both "walk" sprites work but when my Player is in idle it always faces right (idle_right).
At first I thought that something in the tutorial code was causing the engine to think I'm facing always facing right when not moving but now I'm thinking that the "idle" code is simply just producing a result and the sprite reverts back to "idle_right" because it's my default sprite.
My aim is to call the idle_sprite in which direction I last faced (so when moving left and stopping, it would be "idle_left" and vice versa. Having trouble figuring this out so any help or info would seriously be appreciated!
///Player Input & Gravity
//Player Input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 20) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
///Sprite Control
if keyboard_check (vk_left)
{
sprite_index = walk_left;
}
else
if keyboard_check (vk_right)
{
sprite_index = walk_right;
}
else
if direction = 0
{
sprite_index = idle_right;
}
else
if direction = 180
{
sprite_index = idle_left;
}
Below you will find my current code layout in step event of Player (everything up until "///Sprite Control" is part of the tutorial.) The result of this is that both "walk" sprites work but when my Player is in idle it always faces right (idle_right).
At first I thought that something in the tutorial code was causing the engine to think I'm facing always facing right when not moving but now I'm thinking that the "idle" code is simply just producing a result and the sprite reverts back to "idle_right" because it's my default sprite.
My aim is to call the idle_sprite in which direction I last faced (so when moving left and stopping, it would be "idle_left" and vice versa. Having trouble figuring this out so any help or info would seriously be appreciated!
///Player Input & Gravity
//Player Input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 20) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
///Sprite Control
if keyboard_check (vk_left)
{
sprite_index = walk_left;
}
else
if keyboard_check (vk_right)
{
sprite_index = walk_right;
}
else
if direction = 0
{
sprite_index = idle_right;
}
else
if direction = 180
{
sprite_index = idle_left;
}