Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am really new XNA programming, and i am having a big problem. I have a Vector2, spritePosistion, that controls what position the sprite is at, now i want to move it by 1, every time that a player hits the w button, it is having a problem 1 being and int and spritePosistion being a Vector2. So am i doing it wrong or is there a way of getting these things to work together. Here is the code

if (Keyboard.GetState().IsKeyDown(Keys.W))
{
    // This is the problem 
    spritePosition += 1;
}
share|improve this question
2  
0% accept rate doesn't invite answers... –  Gustavo Maciel May 12 '12 at 22:00
2  
You need to study vectors. –  Jonathan Hobbs May 12 '12 at 22:01
add comment

2 Answers

It depends, you're being awfully vague in your question. For instance, in which direction do you want to move? A few examples...

  • Right spritePosition.X += 1

  • Left spritePosition.X -= 1

  • Down spritePosition.Y += 1

  • Up spritePosition.Y -= 1

share|improve this answer
add comment

You said you want to "move the sprite by one" - but in which direction? Try

spritePosition.X += 1;

or

spritePosition.Y += 1;

for X or Y movement.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.