Space Shooter - Shooting
| Category | : Flash | Views | : 163558 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : space-shooter-shooting.zip | ||
| Result | : See the result | ||||
| <<< Previous | Index Series | Next >>> |
This tutorial is a series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. If you haven't learned the previous tutorials, please see Space Shooter Flash Game
This is the second part of the tutorial and we are going to enable the ship to shoot.
Previously we made our ship fly; now we are going to make it shoot and set limits to where it can go.
First we need to make our bullets, right click the library tab, select "New SymbolÂ…" and give it the name "Bullet".
Before clicking OK, click Advanced, select "Export for Actionscript" and make sure the identifier is "Bullet".

We do this because we need to export the Bullet Movie Clip during running time to create many bullets and we will use the name determined in identifier to call it later.
Draw a small bullet, and position it like this:

This is called registration point, in the stage this is the position of the Bullet Movie Clip.
Now open the actions window of the first frame of the Movie Clip and paste this code:
this.onEnterFrame = function()
{
this._x += 12;
if (this._x > 550)
{
this.removeMovieClip();
}
}
"this" is the Movie Clip instance, so if we duplicate 100 bullets each bullet will have the same code.
this._x += 12;
Every frame, the bullet will move 12 pixels to the right.
if (this._x > 550)
{
this.removeMovieClip();
}
If the bullet passed the limits of the screen (550px) it's no longer visible, so we remove it by using this method "removeMovieClip()"Now go to the main timeline, select the first frame and open the actions windows. You will see the previous codes that we have written. Add this code to the old one so we can fire our bullets:
var i = 0;
this.onEnterFrame = function()
{
.
.
.
else if (Key.isDown(Key.DOWN))
{
Ship._y += 5;
}
if (Key.isDown(Key.SPACE))
{
i++;
_root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth());
_root["Bullet" + i]._x = Ship._x + 3;
_root["Bullet" + i]._y = Ship._y;
}
}
More cool tech articles from other blogs.
| <<< Previous | Index Series | Next >>> |
