I have an issue where if the ball hits the paddle just right, it gets locked inside and can't be released. It happens sometimes on the player paddle, but since you have control of it, all you have to to do is move it and it escapes. The computer follows the ball perfectly, so once it gets inside it never can escape, leading to what happens in this video. Now this only happens when I increase the framerate, if it's really low, it kinda, errors out and "goes through" the paddle resulting in a point gained. At least in this case, it's not a noticeable bug and the game continues to play.
Naturally I want the framerate to be as smooth as possible so..., like to sort this out. Here's my code for the very simplistic collision detection. Using 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
}
}
Thanks for the help.