Share this Page URL
Help

Chapter 5. Collision Detection > What Is a Collision? - Pg. 61

61 Chapter 5. Collision Detection What Is a Collision? Detection Using hitTest() Detection Using Math Collision Detection with Advanced Shapes Points to Remember When you're playing a computerized game of pinball, or a platform game like Super Mario Brothers, you probably take it for granted that it has realistic-looking reactions. In pinball, the ball gets hit by the flippers and zooms away; in a platform game, the character lands on a platform or falls to the ground. There is one important thing that has to happen before any of these realistic reactions can take place: There has to be a collision, and the collision must be detected. (OK, that's two things.) Once the collision is detected, a reaction can take place--we'll get into that in the next chapter. In this chapter, we'll discuss the ins and outs of collision detection, using both hitTest(), a method of the MovieClip object sometimes useful for this purpose; and math, which is where the real power lies. We will also address the limitations of collision detection in Macromedia Flash and how you can get around them. What Is a Collision? Before learning how to program collision-detection scripts, it is important to understand what a col- lision is. I know what it sounds like--something big and crashy. And of course in a lot of cases that's true, but for our purposes, we need to get down to a more basic definition than that. Put simply, a collision happens when two separate shapes share one or more points in space. For instance, imagine two circles touching at their edges, such as two billiard balls resting against each other. These two circles share one point; hence, in physics terms they are colliding. Some collisions are simple, such as when the mouse pointer overlaps a movie clip or a button. Other collisions are complicated, such as when a ball bounces off an angled line.