Quick Game Select


Free Site Content
Bookmark This site
All Free games
All Free Toons
Video News feeds
Advertising
Community
Community Forums
Register
Login
Advertisement
Search

Latest 10 Flash games
  Stunt Master
  Do stunts in your car or bike
  Mario DS
  Stomp Goombas and Koopas
  Jewel Cave
  Grab he jewels while avoiding enemies
  Toastache
  Jump on platforms and collect butter
  Galactic Takedown
  Arrange your army, buy turrets, and shoot down the enemy mothership
  Birdys Rainy Day Skipathon
  Help the birdy skip home
  The Terminal
  Use your mech and shoot down the robots being controlled by an enemy AI before it destroys your base
  History of War Romans
  Build an empire by sending out armies and conquering villages
  Ditloid
  Figure out what the phrase is from the clues
  Lifeguard Larry Deluxe
  Save the person that is drowning


Top Rated(5+ votes)
Roll On(5/5)
Microlife(5/5)
Crunchball 3000(5/5)
Bubblez(5/5)
Blueball 2(5/5)
Spectrum Genesis(5/5)
Fuzzy McFluffenstein 3(5/5)
MonsterDen: Book of the dead(5/5)
Mario Combat Deluxe(5/5)
Aeternus Lamnia Duo(5/5)
Two Minute color panic(5/5)
Monster Truck Maniac 2(5/5)
Lastest 12 toons
Primal War 16
Primal War 15
Primal War 14
Primal War 13
Primal War 12
Primal War 11
Primal War 10
Primal War 9
Primal War 8
Primal wars 7
Primal Wars 6
Primal Wars 5
Tutorial Categories
Last 5 Tutorials
Asteroid holes with gradients
Gravitation pull/Circular collisions
Pong tutorial
Basic shooting game
Turret aiming and fire
Asteroids movement and fire
Inertia and directional movement and fire
Enemy movement and Fire
Ship Movement and fire
Moving starfield background



This tutorial will teach you how to make a simple starfield background for your flash game. This is what the product will look like in the end.























This tutorial is made using Macromedia flash MX 2004 professional(or in other words Flash 7 professional edition).

First open up a document 550 in width and 400 in height and make the background black. Draw a big dot, a smaller dot, and an even smaller dot on the document to represent your three stars. Separately select each one of the and go to top menu and do modify-->Convert to symbol and convert them to a movie clips. Call them bigstar, smallstar, and tinystar.

Now you actually need to give them property names. In the three panels below the main document, you'll see a panel called "properties". Expand that

panel and right under the dropdown box where it has movie Clip as the symbol type, there is a blank text box to name your symbol instance. Name the three stars t1, t2, and t3 for simplicity. No you should have something that looks like this when you select all three of the stars(Note that I have 3 layers and put one star on each layer, but this is not neccessary for this.







Now we need to duplicate the star to have many of them at once on the stage and a function to make them move. So click on the first frame of your layer and expand the Actions panel at the bottom to edit the code, it should look like this.









The actual code in the actions section should be this:





Code:


stop();

for (i=1; i<=100; i++)

{

t1.duplicateMovieClip( "t1"+i, i+100,t1 );

}

for (i=1; i<=40; i++)

{

t2.duplicateMovieClip( "t2"+i, i+300,t2 );

}

for (i=1; i<=20; i++)

{

t3.duplicateMovieClip( "t3"+i, i+400,t3 );



}



function loadstar(varname) //loads the clip

{

_root[varname]._x=random(550);

_root[varname]._y=random(400);

_root[varname].speed=random(10)+2;

}

function movestar(varname) //stars

{

_root[varname]._x+=_root[varname].speed;

if(_root[varname]._x>550)

{

_root[varname].reset();

}



}



The stop() at the top stops the movie at this frame and prevents it from going onto the next one.


First we have three for loops to duplicate several copies of our star, we duplicated t1(our tiny star) 100 timesm t2(the medium star) 40 times, and t3(the big star) 20 times. The 2nd parameter(ex. i+100) is very important as that specifies the depth. You cannot have two clips of the same depth on the stage or one will replace the other. The function duplicateMovieClip() simply duplicates whatever movie clip you tell it to duplicate.



The next two functions are loadstar() and movestar(), simply put, one loads the stars onto the stage and the other one moves them. They both take a parameter,varname, which is the name of the clip you want it to move.



Loadstar simply sets the initial x(horizontal) position of the clip at somewhere between 1 and 550, sets the initial y position at somewhere between

1 and 400. _root[varname].speed is how fast the star will move across the stage. We set this to some speed between1 pixel per frame to 10 pixels per frame plus an intial 2 frames per pixel so it won't be too slow.





Movestar moves the star, it says to move the star's x position the number of pixels specified in speed every time a frame loads. It also calls a reset() function to reset the star if it moves past pixel 550 in x-coordinates(moves off the stage). Reset is a function in the movie clip itself(we will talk about this in the next section).



So now you have the basic functions, you still need to call them within the movie clip. So, select one of your star movie clips and open the actions tab

like this:









Paste this code in:



Code:


onClipEvent(load)

{

_root.loadstar(this._name);

function reset()

{

_root.loadstar(this._name);

}



}

onClipEvent(enterFrame)

{

_root.movestar(this._name);



}





The OnClipEvent(load) event is what happens when the clip initially loads(every time a star is duplicated). It basically calls the loadstar function

and passes it the clip name in this._name. It also has a reset function for every time the star needs to be reset. This function also just calls to load function which sets the coordinates and the speed of the star.



onClipEvent(enterFrame) loads every time a frame is loaded, flash's default is 12 frames per second. The onClipEvent just calls the movestar function wewrote earlier and passes it the name to move the star.



Now paste that code into the "Actions" tab of all three stars and your done!



You can grab the source file Here if needed.



Questions and comments about this tutorial can be posted in This thread






Hot Flash Games
Flanders Killer

Final Fight

Pit Dwellers

Advertisement

Top Referrers
1. Java gaming
2. Play Games Club
3. Sonic Mario games
4. AddictingGames.com
5. Bubblebox Games
6. Smashing Games
7. Fast Games
8. Free Flash Gaming Fun
9. Heavy Games
10. Mario Games
11. Baller arcade
12. Net games
13. Newgrounds
14. Internet Games
15. Car Games


[More Links]
[Add your link]
Partners
Links
Other stuff
E-mail me

AIM: Bobjoe6641
More Flash games
Naruto Ninja

Avatar Arena

Conquer Antartica