有人会告诉我在这段代码中做错了什么...我试图在按下键盘上的左箭头时移动一个精灵。但是当我运行代码时,游戏窗口会打开并快速关闭
public class Sprite
{
private Texture2D texture;
private Vector2 position;
public Sprite(Texture2D texture, Vector2 position)
{
// TODO: Complete member initialization
this.texture = texture;
this.position = position;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, Color.White);
}
void Update(KeyboardState keyboardstate, GameTime gameTime)
{
// throw new NotImplementedException();
if (keyboardstate.IsKeyDown(Keys.Left))
{
Velocity = new Vector2(-1, 0);
position+= ((Velocity) *(float) gameTime.ElapsedGameTime.TotalSeconds);
}
}
public Vector2 Velocity { get; set; }
}