Game Development Reference
In-Depth Information
But what about all that stuff in the argument?
These values define the point that you want to use to check for a collision. You can find any single
point by giving two values: an t position and a u position. In this example, you used the center point
of the lh]uan object as the point you want to use in the collision. The third argument, pnqa, just
means “yes, you want to check for a collision using a point and a shape.” (The last argument is called
the shapeflag in the AS3.0 documentation. If you set the shapeflag to b]hoa, depPaopLkejp will just
go back to checking for a collision with the objects' bounding boxes, just as depPaopK^fa_p does.)
Figure 7-29 illustrates how all the elements of collision detection using depPaopLkejp fit together.
The object whose
shape you want
to check for
a collision
The hitTestObject
The x and y coordinates
of a single point you want
to compare against the
object's shape
This just means,
“Yes, let's compare
this point against the
object's shape.”
Add any directives you want to run when
the collision occurs inside the if statement
Figure 7-29. How hitTestPoint works
So what is depPaopLkejp useful for? Let's go back to the cat with the long ears. Suppose that you
designed a game in which it's absolutely crucial to know whether something is touching the tips of the
cat's ears. All you need to do is figure out the t and u coordinates of the points that define those ear
tips, and then use them in a conditional statement using depPaopLkejp.
For example, you know that the tips of the cat's ears are at the very left and right side of the _]p
object, and about 3 pixels from the top. First, you need to define these points, and even though you
could do this directly in the arguments of the depPaopLkejp method, it will make the code a little
more readable if you define them as variables first. You can use some code that looks like this:
Figure 7-30 illustrates these positions.
Now all you need to do is use these points to write two eb statements using depPaopLkejp (you need
one for each ear tip):
Search Nedrilad ::

Custom Search