Wednesday, February 17, 2010
I Feel I Have Arrived...
Large version here.
Phew. I'm feeling pretty good. Why is that? Because the above is my first thing ActionScript 3 that I can say I'm pretty happy with! That's right! I have made great strides in AS3 tonight!
I'm all giddy with the possibilities...
As for the coding itself, there's nothing too awfully insane here. We've got a ship that follows the mouse cursor loosely; it does this by moving the distance between itself and the mouse times a fraction of the distance every frame. In other words, if it's 50 pixels from the mouse and we've moving with .5 drag, it will move 25 pixels, then 12.5 pixels, then 6.25 pixels, etc. etc. until it reaches 0.
The bomb is simply a class that initializes with a movement speed on the y axis of -10. Instantly and in every frame, that movement speed increases by .5, giving the illusion of acceleration.
Once the bomb hits, it is removed from the stage and replaced by a shape tweened circle. I manually animated the growth via timeline, but it would be very possible to do so with straight code. That little rainbow flourish you see as the explosion fades is just me playing with code tweens and the ColorTransform object. I simply tween the ColorTransform from a random color to another random color.
There you have it! AS3...I'm warming up to you!
PS:I found this tutorial to be incredibly helpful in learning to get classes to speak to one another. Be sure to download the AS3 source code. Interestingly enough, I had my "a-ha moment" with the AS2 version of this tutorial...hmm...they must be doing something right!
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDelete