Making my XNA sprite jump properly
Posted
by
Matthew Morgan
on Stack Overflow
See other posts from Stack Overflow
or by Matthew Morgan
Published on 2012-12-04T10:49:08Z
Indexed on
2012/12/04
11:07 UTC
Read the original article
Hit count: 353
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.
© Stack Overflow or respective owner