Game Development Reference
In-Depth Information
The `u variable that's used to figure out the distance between the objects on the y axis is used a little
later in the code.
Now that you know the distance between the objects and their combined total half-widths, you can
find out whether the objects are overlapping on the x axis with this line of code:
r]nkt6Jqi^an9k^fa_p>[D]hbse`pd'k^fa_p=[D]hbse`pd)I]pd*]^o\$`t%7
This is the formula for figuring out whether there's any overlap. Refer to Figure 7-36 for an illustration
of how this works. The variable name kt is shorthand for “overlap on the x axis.”
One new thing in this directive is this:
I]pd*]^o\$`t%
I]pd*]^o is one of AS3.0's built-in methods. (And, yes, it's a static method!) Its job is to find out what
the absolute value of a number is. Absolute values can only be positive; negative numbers that are
forced to be absolute have their sign dropped. Let's imagine that you use I]pd*]^o in a line of code
that looks like this:
I]pd*]^o\$).3%7
It would return this:
.3
Why is this useful for you? If k^fa_p> has a lower t position value than k^fa_p=, the value of `t will
be negative. The negative value would overly complicate the code because you'd need an additional
eb statement to check for it. It's simpler for you just to deal with positive values.
The next bit of code is a long nested eb/ahoa statement:
eb\$kt:,%
w
r]n`u6Jqi^an9k^fa_p=*u)k^fa_p>*u7
r]nku6Jqi^an9k^fa_p>[D]hbdaecdp' ±
k^fa_p=[D]hbdaecdp)I]pd*]^o\$`u%7
eb\$ku:,%
w
eb\$kt8ku%
w
eb\$`t8,%
w
++?khheoekjkjnecdp
kt&9)-7
ku9,7
y

Search Nedrilad ::

Custom Search