Any help?

TheDurka

Member
I'm making a platformer and my character isn't doing a run animation when he is on the ground. He doesn't move and just stands there. I think it's a collision error but idk. Here's my code:
if (!place_meeting(x,y+1,o_wall))
{
sprite_index = s_playerAirborne;
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_playerRun;
}
}


The
if (!place_meeting(x,y+1,o_wall))
y+1 is messing my game up, how do I fix this? I saw how to write this code from Shaun Spalding.
 
Last edited:

Nidoking

Member
Do all of the sprites have the same dimensions and origin? Usually, this means that when you changed sprites, the bottom of the collision box is no longer at the same place.
 

TheDurka

Member
Do all of the sprites have the same dimensions and origin? Usually, this means that when you changed sprites, the bottom of the collision box is no longer at the same place.
Yeah, they are all 24x48 except for the running animation, should I make the running animation 24x48 too?
 
IDK if this is just me, but whenever I write an if statement that looks like this
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
It never works, maybe try formatting it with brackets
 

TheDurka

Member
IDK if this is just me, but whenever I write an if statement that looks like this
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
It never works, maybe try formatting it with brackets
That is the Airborne animation when the player Y is bigger and the player is not touching the ground. When he's not touching the ground he plays a jumping animation and then a falling animation and when he touches the ground he turns back into his normal standing sprite. I don't really know what to fix.
 
Here is what I use for animation, hope it helps


//Update Sprite Index
var _oldSprite = sprite_index;
if (spriteRun != -1) && (_move != 0)
{
direction = _move;
sprite_index = spriteRun;
} else
{
if (spriteIdle != -1)
{
sprite_index = spriteIdle;
}
}
if (_oldSprite != sprite_index) localFrame = 0;

//Update Image Index
SpriteAnimate();


Here is the script SpriteAnimate
function SpriteAnimate(){
#macro CARDINAL_DIR round(direction/90)
#macro FRAME_RATE 60
//Update Sprite
var _totalFrames = sprite_get_number(sprite_index) / 8; //if your sprite only has 2 directions, change 8 to half of the total number of frames in your animation
image_index = localFrame + (CARDINAL_DIR * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;

//If animation would loop on next game step
if (localFrame >= _totalFrames)
{
animationEnd = true;
localFrame = 0;
}else animationEnd = false;


}


Hope this helps!
 
Top