Graphics Programs Reference
In-Depth Information
64
65
66
67
68
69
70
71
// create the motion along the circular path
this.onEnterFrame = function()
{
// update the angle increment based on how far
// _xmouse is from the center of the Stage
var angleChange:Number = Math.round(_xmouse-xo);
startAngle += angleChange;
Test your movie and see what happens. When the cursor is near the center of the
Stage, the objects generally behave as expected. In the center they stop altogether,
and, depending on whether you move the cursor left or right, the objects will rotate
clockwise or counterclockwise. When you move the cursor out a littler farther, weird
things begin to happen. The objects appear to speed up and slow down, sometimes
rotating clockwise, sometimes counterclockwise.
The problem is that the objects are spinning too fast and produce an effect that, in the
movies, are like wagon wheels rotating backwards due to differences in wheel rotation
speed and the film rate. In our case, angleChange gives a number between -320 and
320, since our Stage width is 640 pixels. We need to make angleChange produce a
smaller number.
Step 2: Add a speed factor
Let's define a variable named speedFactor as part of the object characteristics. We'll
set its value to 40, but it can be anything you like.
14
15
16
17
// set the number of objects to be created and startAngle
var numberOfObjects:Number = 8; //object_mc._totalframes;
var startAngle:Number = 0; // starting rotation angle
var speedfactor:Number = 40; // controls speed of motion
In the angleChange calculation, we will divide the number by speedfactor , which will
now yield a number between -8 and 8 after we round it off. We'll use this to update
startAngle , which controls the motion at a more reasonable rate. Make the one-line
change below, test your movie, and check that the objects rotate at variable speeds.
 
Search WWH ::




Custom Search