Game Development Reference
In-Depth Information
AS3.0 has a system for converting local coordinates to global coordinates. As a game designer, this is
something you'll find yourself needing to do all the time. Strangely, however, AS3.0 doesn't make this
easy, and converting local to global coordinates is something that has stumped even very experienced
developers new to AS3.0. To make matters worse, Adobe's documentation on this is far from clear,
especially in the practical usage that you need to put it to in everyday situations such as these.
You won't like this system; it's cumbersome and convoluted. But it's the only way of converting coor-
dinates, it works, and you have to learn to live with it. Don't worry, though; just bookmark this page
and refer to these directions every time you need to do this. It's actually not so bad once you get used
to it!
Here's the process you need to follow to convert local coordinates to global coordinates (don't let this
long list scare you; you'll soon see that it's not quite as hard to implement as it might seem):
1. Import AS3.0's Lkejp class with the import directive eilknpbh]od*caki*Lkejp7. This import
directive should be part of the class definition, along with all the other import directives.
2. Create a new Lkejp object to store the t and u positions of the subobject whose local coor-
dinates you want to convert to stage coordinates. In this example, the line of code might look
like this:
r]nbnkcoNecdpAua6Lkejp9jasLkejp$bnkc*necdpAua*t(bnkc*necdpAua*u%7
Lkejp objects contain two built-in properties: t and u. The t and u coordinates
of the object that you specify in the arguments when you create the Lkejp object are copied into
the Lkejp object's own t and u properties. (Don't worry if this is confusing! You'll look at this
in more detail in a moment.)
3. Use AS3.0's built-in hk_]hPkChk^]h method to convert the new Lkejp object's local coordi-
nates to global coordinates. hk_]hPkChk^]h is a method of the Ikrea?hel class, so it needs to
be called by a Movie Clip object. Usually, the object that calls it is the parent of the subobject.
In the example, the parent is the bnkc object. So to convert the t coordinate, you can use some
code that looks like this:
bnkc*hk_]hPkChk^]h$bnkcoNecdpAua%*t7
4. You need to store this new global coordinate in yet another variable so that you can put it to
some practical use in the program. You can convert the Lkejp object's t coordinate and store
it in a new variable with a single line of code that looks like this:
r]nbnkcoNecdpAua[T6Jqi^an9bnkc*hk_]hPkChk^]h$bnkcoNecdpAua%*t7
5. After all that trouble, you have a variable called bnkcoNecdpAua[T. It contains the global coor-
dinate of the subobject's t position. That's the variable you use if you want to refer to the right
eye's global t position.
6. Hey, not so fast! You're not done yet! You've only converted the t position's coordinate. Repeat
steps 3 to 5 to convert the u position as well. Rinse thoroughly and blow dry.
 
Search Nedrilad ::




Custom Search