Custom class dependencies: Vector2D
Working with vectors – Part 1, Part 2, Part 3
So far everything done in the series “Working with vectors” have been utilities to help with the calculation of trigonometric values. Now we will apply it to something that will be displayed, a MovieClip! Or in this case, what I call a VectorClip.
The VectorClip class simply extends MovieClip, and adds the methods of which we already added to the Vector class that extended Point. A new property of direction
is now complimentary to the existing property of rotation
. Both properties are useful in working with this class.
The overall goal is achieved now that we can move a MovieClip (or any other DisplayObject these methods are applied to) by simply calling the ‘move’ methods which are: move, left, right, forward, and backward. All of these methods are based on a magnitude and angle, which in this case, the angle is the property of direction. The reason the direction property stays separate from the original rotation property is simple. It is because sometimes, we may want to rotate the object without changing it’s direction and vice versa.
There is another Boolean property called rotationBased
. This property, when set to true, simply combines the properties of direction
and rotation
. So that when one is set, the other is also.
After explaining all of this, here are a couple of simple examples. In the second, please click anywhere on the stage. You will see the MovieClip turn and move toward that location. This is all done with the vector movement defined in the VectorClip class.
VectorClip Example:
[swfobj src=”https://jidd.jimisaacs.com/files/2008/08/example-VectorClip.swf” width=”350″ height=”250″ align=”center” required_player_version=”10.0.0″]
AS3 VectorClip Example
VectorClip Example 2:
[swfobj src=”https://jidd.jimisaacs.com/files/2008/08/example-VectorClip2.swf” width=”350″ height=”250″ align=”center” required_player_version=”10.0.0″]
AS3 VectorClip Example 2
Finally here is the class used in the above examples and is the end result of the series. Remember to check to other posts for the required classes for each step of the process. Thank you and enjoy!
com.jimisaacs.display.VectorClip
Comment if you have any questions, or suggestions.
Leave a Reply