Forum: Log-In | Register | Contact | Shop


SwishMax Tutorials And Resources
Where Imagination Is The Creation

 


Add


Simple Spaceship Fire Weapon - Swishmax

Learn how to make a spaceship fire a weapon. (shoot Object)


Controls

Use the Ctrl Button to shoot the weapon, if the weapon does not fire click on the movie then try again.


First Of All

You will need the latest build of swishmax installed on your Computer for this to work.
open swishmax and set the canvas size, for this tutorial i have used 300 x 310 and a frame rate of 25fps.

 

 

Step.1

Create your spaceship or craft whatever you want to call it, if you have no idea i have created an animated gif of the vector craft i have made in the example, right click on the sample below and save as, then import it into your project using file- import.

Ship.gif

 

 

 

Step.2

Name the sprite as craft, Now create your weapon, you can use a circle, rounded rectangle, anything you want for the weapon i have used a rounded rectangle. Once have have you shape that you are happy with group it together as a sprite and name it weapon. place the weapon sprite underneath the craft sprite and at the front of the craft in its firing positin.

 

 

Step.3

Add the following code to the weapon sprite

onEnterFrame() {
if (this._name != "weapon") { //moves weapon along it y axis untill it leaves the play area.
this._y -= 5;
}
}



Step.4

Now group the craft Sprite and the weapon sprite both together inside a new sprte and name it ship now add the following code to the ship sprite.

onLoad () {
var i:Number = 0;
var load:Number = 15; // sets the delay between shots.
}
onEnterFrame() {
if (load > 0) {
load---1;
} else {
if (Key.isDown(Key.(17))) { //key 17 is Ctrl on a standard keyboard
i++;
duplicateMovieClip(_root.ship.weapon,"bullet"+i,i);
load = 15;
}
}
}

 

Thats it, Now press Ctrl+T to test in player
and press the Ctrl button to fire the weapon from the ship.

Note: key 17 is the Ctrl button on a standard keyboard, if it doesnt work for you replace the code with the following.

if (Key.isDown(Key.Space)) {

 

Thank you for reading i hope this tutorial has helped you in some way, If you have any question please feel free to join the forum and ask.