Graphics Programs Reference
In-Depth Information
Exercise 6.3: More Complex Movement
Now that we have things moving in one direction, let's extend what we know. Open
6_3_rockOn.fla in the Chapter 6 folder. Except for the number of objects and a great-
er range of z - values, this file has the same script as the previous exercise. The frame
rate has been increased to 24 frames per second (fps) for faster motion. Test the movie
to see what it looks like. While it seemed somewhat natural for the fish to be swimming
in unison, the rocks look strange all moving at the same rate. We need to have more
variety in their movement. Open 6_3_rockOn_DONE.swf to see where we are headed.
Figure 6.8 Complex translational movement
Step 1: Vary the z -direction movement
Rather than having all the rocks move at the same speed, let's use the random function
to enable each rock to move at a different speed. Change line 27 to the one shown be-
low. For each rock, the -Math.random()*10 generates a number between 0 and -10 to
which a -3 is added. So each rock will have a change in z - value between -3 and -13.
Test your movie to see the difference that different speeds make.
26
27
28
thisObj.z = Math.random() * 300 + 300;
thisObj.dz = -Math.random() * 10 - 3;
}
 
Search WWH ::




Custom Search