00:00
00:00
Newgrounds Background Image Theme

Inkolypso just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss: Starfield

1,472 Views | 4 Replies
New Topic Respond to this Topic

Foss: Starfield 2005-10-28 20:49:01


FOSS Main

-- FOSS: Starfield --

In this topic, you'll find my dynamic starfield engine. As usual and for all FOSS topics, feel free to use this code as you wish, and you shall share your modifications of this engine (if you made some) on this topic.

What should be useful to know before using this engine (links redirects to the corresponding AS topic):

Beginning ActionScript, ClipEvents, Frame functions, Loops and conditions, Variables, Maths basics, Duplicated movie clips, Functions - Basics,

The code:

for (n=1; n<250; n++) {
newStar(n);
}
function newStar(i) {
_root.attachMovie("star_mc", "star"+i, i);
_root["star"+i]._x = random(640);
_root["star"+i]._y = random(480);
_root["star"+i]._alpha = 0;
_root["star"+i].xfactor = (_root["star"+i]._x-320)/20;
_root["star"+i].yfactor = (_root["star"+i]._y-240)/20;
_root["star"+i].alphafactor =int(100*(Math.abs(_root["star"+i].xfactor
)+Math.abs(_root["star"+i].yfactor)))/28;
_root["star"+i].onEnterFrame = function() {
if (this._alpha<this.alphafactor) {
this._alpha += 5
}
this._x += this.xfactor;
this._y += this.yfactor;
if (this._x<0 || this._x>640 || this._y<0 || this._y>480) {
newStar(251+i);
this.removeMovieClip();
}
};
}

Note: tabulations and line breaks were removed to prevent the NG forum from messing the code.

Usage:

Put this code on a frame (root timeline recommended, unless you know how to integrate correctly this code in a movie clip).
This code was created for a Stage size of 640X480, with black background and 25 FPS. For any customisations, post here.

Help and comments:

Feel free to ask customisations of this code to NG users or giving comments on this code here. Further help can be given via email, if it's really necessary (check my profile).

~gorman2001.


website :: hugostonge.com

my job :: we+are

Response to Foss: Starfield 2005-10-28 20:52:43


At 10/28/05 08:50 PM, SpamBurger wrote: Awesome starfield. I may use that in my game. ;)

cool. if u do so, could you send me a link when it will be finished ?


website :: hugostonge.com

my job :: we+are

Response to Foss: Starfield 2005-10-28 20:56:07


woops, forgot the most important:

Example:

Here you can see an example with this code and the specifications described in Usage.


website :: hugostonge.com

my job :: we+are

Response to Foss: Starfield 2005-11-01 20:47:12


*bumpy*


website :: hugostonge.com

my job :: we+are

Response to Foss: Starfield 2005-11-01 20:54:01


nice lol but its really light so u cant hardly c them lol.


*User Page under construction*

BBS Signature