What Is a Collision?


Before learning how to program collision-detection scripts, it is important to understand what a collision 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.

graphics/05fig01.gif

In this chapter we'll cover several of the most common types of collision detection, including those having to do with intersections or collisions of lines with lines, circles with lines, and rectangles with other rectangles.

graphics/05fig02.gif

As I mentioned earlier, there are two main types of programmatic collision detection used in Flash: the use of the hitTest() method of the MovieClip object, and the use of math to determine if a collision has occurred.

As you will see from what follows in this chapter, hitTest() has its uses but is vastly inferior to collision-detection scripts that use math. By using math to determine collisions, not only can you determine if a collision is happening, but in some cases you can also tell if a collision is about to happen, and at precisely which position this collision will occur. We need this level of precision for some of the more advanced types of games, such as pinball or billiards.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net