Making my XNA sprite jump properly
- by Matthew Morgan
I have been having great trouble getting my sprite to jump. So far I have a section of code which with a single tap of "W" will send the sprite in a constant velocity upwards. I need to be able to make my sprite come back down to the ground a certain time or height after begining the jump. There is also a constant pull of velocity 2 on the sprite to simulate some kind of gravity.
// Walking = true when there is collision detected between the sprite and ground
if (Walking == true)
if (keystate.IsKeyDown(Keys.W))
{
Jumping = true;
}
if (Jumping == true)
{
spritePosition.Y -= 10;
}
Any ideas and help would be appreciated but I'd prefer a modified version of my code posted if at all possible.