Making Orbit Trails in Flash

Let's continue with previous 'orbit' tutorial. In order to create new 'planetary system' just add single orbit function call:

orbit(planetMovieClip, satelliteMovieClip, _distance, _speed);

This will make satelliteMovieClip orbit around planetMovieClip at distance _distance with speed _speed.

Further you can create another smaller satellite to orbit around satelliteMovieClip, etc ... This system doesn't have any gravity variables, just plain circular movement.

Now, to create simple trails, insert new movie clip, any image will do, but for start, make something simple, like 4 pixels radius white circle. Enter 'trailMC' as linkage name and add next code:

// create trail movie clip
var mc:trailMC = new trailMC();
mc.x = sat.x;
mc.y = sat.y;

This code should go at the bottom of doEveryFrame function. Take a look at result file image:

As you can see, if you make star, planets and moons movie clips have alpha = zero, then you get easy to use shapes generator ... or something like that.

Since trails movie clip can be anything you think of, you can see how powerful this technique can be.

If drawing shapes it's not your goal and rather you need just trails, you can make them disappear after a while. One way to do it is to use next code inside trailMC (or use Timer class):


this.addEventListener(Event.ENTER_FRAME, onFrame);

function onFrame(evt:Event):void
if (alpha > 0)
alpha -= 0.05;
} else {
this.removeEventListener(Event.ENTER_FRAME, onFrame);

In next post I'll show you how to use drawing API instead of movie clips for making orbit trails.

Thanks for reading.


Post a Comment