0

有人会告诉我在这段代码中做错了什么......每当按下键盘上的左箭头时,我都会尝试移动精灵。但是当我运行代码时,游戏窗口会快速打开并关闭 prtty

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; }

}
4

0 回答 0