Game Development Reference
In-Depth Information
You can translate it into ActionScript like this:
eb$_]n*depPaopK^fa_p$s]hh%%
w
_]n*ckpk=j`Opkl$?N=OD%7
y
The depPaopK^fa_p method is attached to the end of the _]n object with dot notation. It has an argu-
ment, $s]hh%, which contains the name of the object that you want to check for a collision. Figure 7-2
shows how this all fits together.
The first
object
The hitTestObject
method
The second
object
if(car.hitTestObject(wall))
{
car.gotoAndStop(CRASH);
}
Add any directives you want
to run when the collision occurs
inside the if statement
Figure 7-2. Use the hitTestObject method inside a conditional
statement to check for a collision between two objects.
Usually you use the depPaopK^fa_p method inside the conditional statement of an eb statement. If
the objects are touching, the method returns a Boolean value of pnqa, and the directives inside the eb
statement run. If it returns a value of b]hoa (if the objects are not touching), the directives inside the
eb statement don't run.
It's amazing what kind of power the depPaopK^fa_p method can give you. In the examples in the fol-
lowing pages, you'll be looking at how you can use it to do the following:
Change text in a dynamic text field
Trigger a change of state
Reduce a health meter
Update a score
Pick up and drop an object
Create an environmental boundary (using depPaopLkejp)
Block an object's movement
With a little imagination, you'll be able to use these techniques to produce a richly varied number of
different kinds of games.
 
Search Nedrilad ::




Custom Search