• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

GameMaker Running animation is only using first frame.

R

realisticturtle

Guest
I posted this yesterday, but I got a few comments telling me to post the code with it. I'm posting it again with the code. Can someone please help me?

Code:
//Get Player Input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,O_Wall)) && (key_jump)
{
    vsp = -7;
}

//Horizontal Collision
if (place_meeting(x+hsp,y,O_Wall))
{
    while (!place_meeting(x+sign(hsp),y,O_Wall))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}

//Horizontal Movement
x = x + hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,O_Wall))
{
    while (!place_meeting(x,y+sign(vsp),O_Wall))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
};

//Vertical Movement
y = y + vsp;

//Running Code
if (keyboard_check(vk_left) = true)
{
    sprite_index = S_Player_Running;
}
else {
    sprite_index = S_Player;
};

if (keyboard_check(vk_right) = true)
{
    sprite_index = S_Player_Running;
}
else {
    sprite_index = S_Player;
};

//Animation
if (!place_meeting(x,y+1,O_Wall))
{
    sprite_index = S_Player_Airborne;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = S_Player;   
    }
    else
    {
        sprite_index = S_Player_Running;
    }
}

if (hsp !=0) image_xscale = sign(hsp);
 
My bad, I missed the line where you are resetting the image speed.
I can't honestly see the problem there unfortunately. Sorry, dude.

Unrelated to the problem, there is a bunch of redundant code changing the sprite index too.
 
R

realisticturtle

Guest
My bad, I missed the line where you are resetting the image speed.
I can't honestly see the problem there unfortunately. Sorry, dude.

Unrelated to the problem, there is a bunch of redundant code changing the sprite index too.
Yeah, I put that in before the animation. I should probably remove that now. Thanks.
 
Is there perhaps somewhere else in your object that you are setting image speed to zero? I've been staring at your code for a bit and I can't see why you have the problem that you do...
 
R

realisticturtle

Guest
Is there perhaps somewhere else in your object that you are setting image speed to zero? I've been staring at your code for a bit and I can't see why you have the problem that you do...
I removed the bit on redundant code that you mentioned, and that did the trick. Thank you for your help!
 
Top