EDIT: I changed the origin of the run sprite to the center, and it is no longer hovering above the jumping sprite. It now flashes in the same location as the run sprite when moving to the side. Everything else is the same.
When I move side to side, the jump sprite moves along the ground while a single frame of the running sprite animation shows up above it and to the side. Both of the sprites flash when this happens. While moving sideways, the sprite slowly sinks into the floor. Jumping works just fine.
I'm very new to game maker and programming in general, so I'm probably making some dumb mistakes. Everything was working fine before I added the "animate" section. Here's the code I'm using:
//get player input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
//react to imput
move = key_right + key_left;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}
//horizontal collisions
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 collisions
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//animate
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wall))
{
if (move!=0) sprite_index = spr_player_run; else sprite_index = spr_player_idle;
}
//else
//{
if (vsp < 0) sprite_index = spr_player_jump //; else sprite_index = spr_player_fall;
if (vsp > 0) sprite_index = spr_player_jump
//}