Hey guys, I was recently working on a new game www.createage.com/Game/main.html and I needed to get a cool starfield effect, this really isn’t a big deal but I figured that you guys could mess around with it, I don’t know do whatever you want with it really, the class Definition is as follows:
// put in flash===== var starfield = new Starfield(_root, 300, 5, -1);
class Starfield
{
private var target : MovieClip;
public function Starfield (target : MovieClip, starCount : Number, maxSpeed : Number, dir : Number)
{
this.target = target;
createStars (starCount, maxSpeed, dir);
}
private function createStars (starCount : Number, maxSpeed : Number, dir : Number) : Void
{
for (var i = 0; i < starCount; i ++)
{
var mc;
var dist : Number = Math.round (Math.random () * 100);
mc = target.createEmptyMovieClip ('star' + i, i);
mc.lineStyle (1, 0xFFFFFF, dist);
mc.lineTo (0, 1);
mc._x = Math.random () * 550;
mc._y = Math.random () * 400;
mc.speed = (dist / 100) * maxSpeed;
mc.onEnterFrame = function ()
{
if (dir >= 0)
{
this._x += this.speed;
if (this._x > 550)
{
this._x = 0;
}
} else
{
this._x -= this.speed;
if (this._x < 0)
{
this._x = 550;
}
}
}
}
}
}
You guys should know how to use it ;), anyway enjoy.
… oh yeah if you use this, the dots are WHITE so set your background to a dark color.
-Michael