by
kirupa | 23 October 2005In the
previous page, I finished
explaining what all of the ActionScript code does. In this page, I will
summarize what was discussed in the past five pages.
Occasionally, for longer tutorials, I will try to provide a quick English-only
summary of the code in a few paragraphs. That may help to give you a better idea
of how the code spread across the previous pages fits together.
When you click your mouse at a target, your mainCircle movie clips begins to
move in that direction. The code for the movement is based on Lostinbeta's
tutorial.
Here is your objective: you want any objects that lie in the mainCircle's path
to move out of the way. You need to predict a collision before it happens.
You check for collisions by sending out a number of path circles that
propagate towards your final target. The number of circles you send out is
determined by your steps variable. Any object that collides with any of
the path circles is instantly added to an array (final_targets). In the
end, the final_targets array contains the name of every obstacle that is in the
mainCircle's path.
Once you have a list of names in your final_targets array, you realize that
they must be moved or else face collision with mainCircle. Using the moveAway
function, you cycle through each name found in the final_targets array and move
those named objects out of the way.
All of the above happens before your mainCircle has even moved a few pixels!
This tutorial relied heavily on code and ideas from the
following tutorials:
Easing on Mouse Click (by
lostinbeta)
Collision Detection Among Multiple Objects
Finding Values in an Array
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

 |
page 6 of 6 |
|
|