Game Development Reference
In-Depth Information
The root property
The robot needs to know what it should follow. The following directive in the kjAjpanBn]ia event
handler assigns the lh]uan object as its target:
r]np]ncap9Ikrea?hel$nkkp%*lh]uan7
This is something you haven't seen before. The directive uses the nkkp object.
As you know, op]ca represents the main stage of the Flash movie. However, AS3.0 also allows you to
access the movie's main timeline. You can access the timeline by using the keyword nkkp. The lh]uan
object is a property of the stage, but it's also a property of the main timeline. That means you can
access the lh]uan object using the dot notation, like this:
nkkp*lh]uan
For the AS3.0 compiler to be happy with this, however, you have to cast nkkp as a Ikrea?hel. So all
you need to do is force its type, like this:
Ikrea?hel$nkkp%*lh]uan
Using this format, you can access any object on the main stage. It's important to remember, how-
ever, that this works only for objects that are on the main stage. If the lh]uan object is a child of
another Movie Clip object, such as `qjcakjKja*lh]uan, using nkkp won't work. You'll need to use
Ikrea?hel$l]najp% like this:
Ikrea?hel$l]najp%*lh]uan7
The preceding directive also works in the current code.
nkkp also refers to the document class. If you want to access your document class from
another class, target it as Ikrea?hel$nkkp% . If you don't have a document class, AS3.0
automatically creates one for you called I]ejPeiaheja . You don't need to worry much
about this, but it's interesting to know that it happens behind the scenes.
Moving the object
Once the robot knows what its target is, it calculates the distance between itself and the target using
the formula you looked at earlier in the chapter. If the distance is less than the N=JCA value (which is
.,,), the robot moves.
It moves using a variation of the easing formula discussed earlier in the chapter. It's a little more com-
plex, however, because you want to limit the robot's speed and the rate at which it turns. Here are the
steps the code takes and the formulas it uses to accomplish each task:
1. The code finds out how far to move the object and assigns these values to ikraT and ikraU
variables:
r]nikraT6Jqi^an9PQNJ[OLAA@&`t+`eop]j_a7
r]nikraU6Jqi^an9PQNJ[OLAA@&`u+`eop]j_a7
 
Search Nedrilad ::




Custom Search