How to make my sprite jump properly?
- by Matthew Morgan
I'm currently working on a 2D platformer in XNA. I have, however been having some trouble with creating a fully functional jumping algorithm. This is what I have so far:
if (keystate.IsKeyDown(Keys.W))
if (onGround = true) //"onground" is true when the collision between the main sprite and the ground is detected
{
spritePosition.Y = velocity.Y = -5;
}
So, the problem I am now having is that as soon as the jump starts the variable "onGround" = false and the sprite is brought back the ground by the simple gravity I have implemented. The other problem I have is creating a limit to the height after which the sprite should automatically return to the ground.
Any advice or suggestions would be greatly appreciated.