Windows run sprite animation is not working.

V

vleermuis2003

Guest
i am just new to gamemaker studio 2 and programming itself. and still learning the basics, but now i ran in another issue i can't figure out.

i am a little bit struggling with my code for moving with my sprites. but everything seems to work fine now, but the only issue i still got is that my running sprite stops already after 1 frame while i am still moving.

i don't know what i am doing wrong so i hope someone could help me out!

here is my code for the animated sprite movement:

GML:
//sprite animation movements
if (x > xprevious)
{
    image_speed = 1;
    sprite_index = PLAYERRUN;   
}

if (x < xprevious) 
{
    image_speed = 1;
    sprite_index = PLAYERRUN;                               
}

if (y > yprevious)                                   
{
    sprite_index = PLAYERJUMP;
    image_index = 1;
    image_speed = 1;
    if(place_meeting(x,y,objectWALLMETAL)) and hspeed = 0
    {
       sprite_index = PLAYER;
       image_speed = 0;
    }
    
    if(place_meeting(x,y,objectWALLMETAL)) and hspeed != 0
    {
       image_speed = 1;
       sprite_index = PLAYERRUN; 
    }
    
    if(place_meeting(x,y,ObjectROCKANDGRASSPATH))and hspeed = 0
    {
       sprite_index = PLAYER;
       image_speed = 0;
    }
    
    if(place_meeting(x,y,ObjectROCKANDGRASSPATH)) and hspeed != 0
    {
       image_speed = 1;
       sprite_index = PLAYERRUN;
    }
}

if (y < yprevious)
{
    sprite_index = PLAYERJUMP;
    image_index = 0;
    image_speed = 1;
    if(place_meeting(x,y,objectWALLMETAL)) and hspeed = 0
    {
       sprite_index = PLAYER;
       image_speed = 0;
    }
    
    if(place_meeting(x,y,objectWALLMETAL)) and hspeed != 0
    {
       image_speed = 1;
       sprite_index = PLAYERRUN  ;
    }
    
    if(place_meeting(x,y,ObjectROCKANDGRASSPATH)) and hspeed = 0
    {
       sprite_index = PLAYER;
       image_speed = 0;
    }
    
    if(place_meeting(x,y,ObjectROCKANDGRASSPATH)) and hspeed != 0
    {
       image_speed = 1;
       sprite_index = PLAYERRUN;
    }
}

if (hspeed = 0) and (vspeed = 0)
{
    sprite_index = PLAYER;
    image_speed = 1;
    
}
 

Nidoking

Member
You keep setting image_index to 0 or 1 if y is not equal to yprevious. It's possible that this is happening regularly as you run, and you just don't notice it because the sprite_index is immediately set back to PLAYERRUN.
 
V

vleermuis2003

Guest
Thanks! this helped me I see it now,

i removed the image_index lines, and now it is working!
 
V

vleermuis2003

Guest
hello i hope someone sees this, but i now kinda have a little problem. i made my enemy create a object named deadenemy, also i set a collision with the ground objects with solid = true; for the dead enemy object, however after a couple of seconds it just drops through the ground.... does anyone know how i could fix this and what might be the issue?
 

Nidoking

Member
Sounds like you're not setting gravity to 0 when the instance is on the ground, so it continues to build up vspeed until it jumps to the far side in one step.
 
V

vleermuis2003

Guest
i added gravity = 0 for when the death enemy object meets the ground but that doesn't seem to change anything.

maybe that you can spot something within my code that might be wrong?

or maybe you know how i could fix this. or might it be something with my sprite??

here is my code for the dead enemy object:

GML:
if(done = 0)
{

vspeed = vspeed + gravity;

//Horizontal Collision
    
if (place_meeting(x+hspeed,y,objectWALLMETAL))
{
                 while(!place_meeting(x+sign(hspeed),y,objectWALLMETAL))                     //WALLMETAL
                    {
                       x = x + sign(hspeed);
                    }
hspeed = 0;
}

//Horizontal Collision
    
if (place_meeting(x+hspeed,y,ObjectROCKANDGRASSPATH))
{
                 while(!place_meeting(x+sign(hspeed),y,ObjectROCKANDGRASSPATH))               //ROCKANDGRASSPATH
                    {
                       x = x + sign(hspeed);
                    }
hspeed = 0;
}
x += hspeed;

//vertical collision
if (vspeed > 0)
        {
            done = 1;
            image_index = 1;
        }
if (place_meeting(x,y+vspeed,objectWALLMETAL))
{
       while (!place_meeting(x,y+sign(vspeed),objectWALLMETAL))                //WALLMETAL
             {
               y = y + sign(vspeed);
             }
    vspeed = 0;
}

if (vspeed > 0)
        {
            done = 1;
            image_index = 1;
        
        }
if (place_meeting(x,y+vspeed,ObjectROCKANDGRASSPATH))
{
       while (!place_meeting(x,y+sign(vspeed),ObjectROCKANDGRASSPATH))         //ROCKANDGRASSPATH
             {
               y = y + sign(vspeed);
             }
    vspeed = 0;
}
y = y + vspeed;
}

if(place_meeting(x,y,ObjectROCKANDGRASSPATH))
{
        gravity = 0
}

if(place_meeting(x,y,objectWALLMETAL))
{
        gravity = 0
}
i tried some thing with the code but nothing really seems to do anything.

here also a video to see what happens:

 

Nidoking

Member
if(place_meeting(x,y,ObjectROCKANDGRASSPATH)) { gravity = 0 }
This never happens. You've moved to the point of contact, so you're sitting right on top of the ground, but here you're checking for overlap. You either need to set gravity to 0 during the collision check above, or check for whether the ground is directly below you here (y + 1).
 
V

vleermuis2003

Guest
ahh yes ofcourse! this worked for me! needed to add some to the x too and i did the y a little bit higher but thats probably something to do with the sprites.

however it is fixed now, thanks a lot! ;D
 
Top