Border-based collision detection involves incrementally searching outward from Actor
until either a collision is detected, or it is determined there are no obstacles in the way. The method finds the edge (or border) of the item collided with. This method is especially useful when objects need to bounce off each other or one object is landing on another and needs to remain on that object for a certain amount of time, for example, when a user-controlled Actor
is jumping on a platform. We will introduce this method of collision detection in this chapter, as well as use it in upcoming chapters.
The at offset versions of Greenfoot's collision detection methods are well suited to border-based collision detection. They allow us to check for a collision at a certain distance, or offset, from the center of the calling Actor
. To demonstrate the use of this method, we will change the implementation of the canMarch...