Graphics Programs Reference
In-Depth Information
Step 4: Display the object on the screen
Again, just as we had before, we need a function to display the object on the screen.
We will use the generic argument thisObj as we did in the last step. Other than that,
everything else is a repeat of earlier displayObj functions.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// display the object on the screen
function displayObj(thisObj)
{
// calculate the distance ratio dr
var dr:Number = d/(d + thisObj.z);
// calculate the screen coordinates xs,ys
var xs:Number = thisObj.x * dr;
var ys:Number = thisObj.y * dr;
// set the location of the object on the Stage
// note minus sign for y is because the y-axis
// in Flash points down instead of up
thisObj._x = xo + xs;
thisObj._y = yo - ys;
// set the size as a percent of distance ratio
thisObj._xscale = thisObj._yscale = 100 * dr;
// set object depth based on its z-location so that
// closer objects are on top of farther objects
thisObj.swapDepths(Math.round(-thisObj.z));
}
Step 5: Create the motion along the path
The next step is to set the object in motion on its circular path. There is very little to
do. We need an onEnterFrame handler to loop over the frame. Each time we just need
to update the angle, place the object in its new location in 3D space, and display it on
the screen. Add the lines shown, and test your movie to check that the motion follows
the dark gray circle.
Search WWH ::




Custom Search