0
http://pastebin.com/YTiNw7rX我該如何解決這個「槳跳」毛刺在我的代碼?
如果測試代碼出來,將槳一直推到屏幕的頂部,放開它,槳會跳下幾個像素。我似乎無法弄清楚如何解決這個問題。我會想象它與紋理有關。
編輯:感謝
http://pastebin.com/YTiNw7rX我該如何解決這個「槳跳」毛刺在我的代碼?
如果測試代碼出來,將槳一直推到屏幕的頂部,放開它,槳會跳下幾個像素。我似乎無法弄清楚如何解決這個問題。我會想象它與紋理有關。
編輯:感謝
這是發生了什麼:
你持有的關鍵。
該功能檢查和/或調整當前Y
。
該功能根據您的按鍵更新當前的Y
。
當前Y
顯示在屏幕上。
你放開了鑰匙。
該功能檢查和/或調整當前Y
。
修正的Y
顯示在屏幕上,導致從前面的Y
跳轉。
所以,你將要更新當前Y
以前檢查,之後吧。
protected override void Update(GameTime gameTime)
{
// Allow the game to exit.
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// Update the paddles according to the keyboard.
if (Keyboard.GetState().IsKeyDown(Keys.Up))
PongPaddle1.Y -= paddleSpeed;
if (Keyboard.GetState().IsKeyDown(Keys.Down))
PongPaddle1.Y += paddleSpeed;
// Update the paddles according to the safe bounds.
var safeTop = safeBounds.Top - 30;
var safeBottom = safeBounds.Bottom - 70;
PongPaddle1.Y = MathHelper.Clamp(PongPaddle1.Y, safeTop, safeBottom);
PongPaddle2.Y = MathHelper.Clamp(PongPaddle2.Y, safeTop, safeBottom);
// Allow the base to update.
base.Update(gameTime);
}