Graphics Programs Reference
In-Depth Information
14
15
16
// define the total frames in the object movie clip
var totalFrames:Number = object_mc._totalframes;
Step 5: Rotate the object on its circular path
It's time to get the object rotating about its own axis as it follows the circular path.
Let's begin with line 72 even though no changes are necessary here. We need to
update the angle increment
angleChange
, which is the amount that the angle changes
as it moves in its circular path. This amount is based on how far the cursor is from the
center of the Stage. This difference is divided by
speedfactor
to control how fast the
object moves. The value of
angleChange
is then added to
startAngle
to determine the
location of the object on the circular path.
70
71
72
// update the angle increment based on how far
// _xmouse is from the center of the Stage
var angleChange:Number = Math.round((_xmouse - xo)/
speedfactor);
startAngle += angleChange;
73
74
75
76
// use the angle to set the frame position
thisFrame = 1 + Math.round(startAngle*totalFrames/360)%
totalFrames;
Line 76 is a bit tricky. We want to create a relationship between
startAngle
and a
corresponding frame in
object_mc
, which we'll call
thisFrame
. What we need is that
the ratio of
startAngle
to 360 degrees is the same as the ratio of
thisFrame
is to
totalFrames
. Expressed as an equation, we have
startAngle/360 = thisFrame/totalFrames
from which we get
thisFrame = startAngle*totalFrames/360
We can apply the modulo (%) function to the quantity on the right above so that only
the numbers in the range -(
totalFrames-1
) through +(
totalFrames-1
) are gener-
ated. In our specific case, this means the numbers -35 through +35, including 0.
Since our object has 36 frames, we need to add 1 to
thisFrame
.
Search WWH ::
Custom Search