XNA Movement Question
Posted: Fri Jan 27, 2012 6:01 am
So I was playing around in XNA earlier, and I felt like the movement of the sprite was really choppy. So I tried to set up a sort of smoothing code
And its setup in a gameloop that looks Like
It worked perfect when I just had the PlayerXY.X +=50; instead of the For loop. However when I use the for loop nothing happens when I press the space key.
Think you guys know whats wrong? Thanks!
Code: Select all
private void UpdateInput()
{
KeyboardState newState = Keyboard.GetState();
if (newState.IsKeyDown(Keys.Space))
{
for (int i = 0; i > 10; i++)
{
PlayerXY.X += i;
UpdateLoc();
}
if (!oldState.IsKeyDown(Keys.Space))
{
}
}
else if (oldState.IsKeyDown(Keys.Space))
{
for (int o = 10; o < -1; o--)
{
PlayerXY.X += o;
UpdateLoc();
}
}
oldState = newState;
}
private void UpdateLoc()
{
position = new Vector2(PlayerXY.X, PlayerXY.Y);
}
Code: Select all
UpdateInput();
UpdateLoc();
Think you guys know whats wrong? Thanks!