Graphics Programs Reference
In-Depth Information
There's one more observation that we need to make. If you test your movie and look
closely, you will notice that many of the rocks go outside of the Stage area before they
reach the z-value necessary to recycle them. Since we can't see them once they are off
the Stage, it makes sense to relocate them back in deep space whenever they are no
longer visible to us.
Let's add a simple test to our script that will do what we want. We'll just check to see
if the _x value of each object is either less than 0, which means it is off the Stage on
the left, or greater than the width of the Stage, which means that it is off on the right.
Similarly, we'll check to see if the _y value is less than 0 or greater than the Stage
height, which means it is off the top or bottom. We'll also place the check for an object
being too close to the viewer on a single line in line 70 for better readability.
69
70
71
72
73
74
75
76
77
// check if the object is too close to the viewer
if ( thisObj.z <= -d + 30) { placeObj(); }
// check for going outside of the Stage area
if ( thisObj._x < 0 ) { placeObj(); }
if ( thisObj._x > Stage.width ) { placeObj(); }
if ( thisObj._y < 0 ) { placeObj(); }
if ( thisObj._y > Stage.height) { placeObj(); }
Save your file as 6_3_rockOn_DONE.fla and test your movie. It should appear quite
a bit different from what we started out with. Have a safe journey.
Tip: In the two previous exercises we used swapDepths() to perform a z-sorting on
the objects so that objects closer to us would be in front of those farther away. Is that
requirement necessary in this exercise?
Rotation in the x-z Plane
As we saw earlier, there are three rotational degrees of freedom about the three coordi-
nate axes. We explored some of the possibilities of rotation about the z-axis in Chapter
5 since it corresponds to normal 2D rotation. We also saw that by distorting a circular
path into an elliptical one that we could simulate rotation about the y-axis in the x-z
plane. Let's use what we did there to provide a jumping-off point to look at actual 3D
rotation in the x-z plane shown in Figure 6.9.
 
Search WWH ::




Custom Search