How to make my sprite jump properly?

Posted by Matthew Morgan on Game Development See other posts from Game Development or by Matthew Morgan
Published on 2012-11-28T17:02:06Z Indexed on 2012/11/28 17:20 UTC
Read the original article Hit count: 213

Filed under:
|
|

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.

© Game Development or respective owner

Related posts about XNA

Related posts about c#