Game Development Reference

In-Depth Information

This returns a number in
radians
. Unfortunately, this is not useful for rotating Movie Clip objects.

You need to convert this number to
degrees
, which is the type of value expected by the nkp]pekj

property.

To convert radians to degrees, you can use a simple calculation: multiply the value in radians by 180

divided by Pi (3.14). AS3.0 has a built-in function called I]pd*LE that returns the value of Pi, just to

make things easier for you. Here's what the final line of code might look like:

I]pd*]p]j.$-()0%&$-4,+I]pd*LE%

This gives you a rounded-off value in degrees:

-0/

Figure 9-20 shows what this looks like in the example.

90

X

143 degrees

3

5

6

0

1

2

4

1

2

Y

3

180

0

4

5

270

Figure 9-20.
Use AS3.0's built-in Math.atan2 function to find the angle of rotation.

Great! You now have a number you can use to rotate the frog. You can use it in a directive like this:

bnkc*nkp]pekj9I]pd*]p]j.$-()0%&$-4,+I]pd*LE%7