我有一个问题,如果球恰到好处地击中桨,它会被锁定在里面并且无法释放。它有时会发生在玩家的桨上,但由于您可以控制它,您所要做的就是移动它并逃脱。计算机完美地跟随球,所以一旦它进入它就永远无法逃脱,导致了这个视频中发生的事情。现在这只发生在我增加帧速率时,如果它真的很低,它有点错误并“通过”桨导致获得一分。至少在这种情况下,这不是一个明显的错误,并且游戏继续进行。
自然,我希望帧率尽可能平滑,所以......,想解决这个问题。这是我用于非常简单的碰撞检测的代码。使用 UIImageViews。
if (CGRectIntersectsRect (ball.frame, playerPaddle.frame))
{
if (ball.center.y < playerPaddle.center.y) //hits the "top" of the computer paddle
{
AudioServicesPlaySystemSound (hitSound);
ballVelocity.y = -ballVelocity.y; // turn ball around if collide
}
}
if (CGRectIntersectsRect (ball.frame, computerPaddle.frame))
{
if (ball.center.y > computerPaddle.center.y) //hits the "bottom" of the computer paddle
{
AudioServicesPlaySystemSound (hitSound);
ballVelocity.y = -ballVelocity.y; // turn ball around if collide
}
}
谢谢您的帮助。