Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In this section, you'll abandon the built-in hitTest family of methods and take collision detection into your own hands. This involves using the distance between two objects to determine whether they have collided.
Taking it to the real world, if the center of your car is 100 feet from the center of my car, you know that the two cars are far enough apart that they couldn't possibly be touching. However, if both of our cars are 6 feet wide and 12 feet long, and the center of my car is 5 feet from the center of your car, you can be pretty certain there is some twisted metal involved, and some insurance papers to fill out. In other words, there is no way for the centers to be that close together without some parts of the cars touching. That's the whole concept behind distance-based testing. You determine the minimum distance required to separate the two objects, calculate the current distance, and compare the two. If the current distance is less than the minimum, you know they are hitting.