||Animating Graphics in Cocoa, Part 1|
|Subject:||Faulty collision method|
The collision method given will not handle corner-collisions correctly. If both x & y coordinates are out of the bounds, the checkCollision method will only flip the y coordinate: this is due to the use of if... else if rather than two ifs.
In most cases, this won't be a problem, as most collisions will not occur at the corners. However, if the collision does occur at a corner, only delta y will be flipped.
This will result in the x-coordinate of the ball to be outside the intended display bounds. Because the x-coordinate is incremented even though it should have been flipped, the ball is moved further from the intended view area. After this, the ball's x position will be stuck until the next y-collision, (or possibly longer) which is not the desired effect.