Graphics Programs Reference
In-Depth Information
43
44
45
46
47
// use space bar & shift keys to control direction
if ( Key.isDown(Key.LEFT ) ) { d -= 1; }
if ( Key.isDown(Key.RIGHT) ) { d += 1; }
}
When the Left Arrow key is pressed, if the dolphins are rotating clockwise about their
own registration points, their rotation will slow down as the value of d decreases until
ultimately their motion will become counterclockwise. If the Left Arrow key continues
to be pressed, their counterclockwise motion will speed up. A similar but opposite
behavior will occur when the Right Arrow key is pressed. Save your movie with the
name 5_3_dolphinSwim1.fla and check that it's working properly .
Step 4: Add additional user interactivity
There is one other keyboard control that would be nice to have, and that is to use the
spacebar and Shift keys to decrease and increase the number of objects respectively.
This takes just a little more work than the others but produces some very nice effects.
Basically we want to use these keys to adjust the numberOfObjects variable. We can
do this easily enough, but it also means that we must perform a new calculation of the
circleAngle . The remaining task is then to either add new objects or remove exist-
ing ones. To accomplish this, we will first define an initObjects() function that will be
built by inserting a few new lines around some of the code that we are already using.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// initialize the number of objects
function initObjects()
{
// calclate the angle between any two objects
circleAngle = 360/numberOfObjects;
// create the objects
for (i = 0; i < numberOfObjects; i++)
{
object_mc.duplicateMovieClip("object"+i, i)
}
}
initObjects();
 
Search WWH ::




Custom Search