Spawning Objects
The two demonstration projects we'll build this week show how to work with a document class to generate instances of Movie Clips on the fly. I refer to this procedure as spawning objects.
In the first demo below, 150 instances of a simple bouncing ball are spawned at point 0,0 (the upper left corner of the screen). They then head off in random directions, at random speeds, ending up in unpredictable or Brownian motion.
The bouncing-ball code is of course almost identical to the code we wrote in the second week of this class, except for the unified starting point.
In our second project, we use our familiar ballistic Movie Clip to simulate raindrops gathering and then falling from the top of the screen. Again, the animation code is a simplified version of our original 2-D bouncer. These objects wait a random amount of time before they move, however. That effect is obtained by setting a locking variable on the animation routine, and generating a random number to unlock.
See the Code Resources page for source files, listed under 10-05-09.
|
|