2012-04-28 28 views

回答

1

這是發生了什麼:

  1. 你持有的關鍵。

  2. 該功能檢查和/或調整當前Y

  3. 該功能根據您的按鍵更新當前的Y

  4. 當前Y顯示在屏幕上。

  5. 你放開了鑰匙。

  6. 該功能檢查和/或調整當前Y

  7. 修正的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); 
}