Article

Build a Shoot-em-up Game in Flash MX

Page: 1 2 3 4 Next

Create the Cross-Hair

Create a new layer called 'aim/fire' above the 'Targets' layer. Create a new movie clip by pressing (Ctrl + F8) and name it 'crosshair'. The symbol should have opened up for editing, so create an additional layer and name it 'Actions'. In frame 1, add a stop action:

stop();

Name the original layer 'Image' and import your cross hair image into Frame 1, aligning it with the centre of the stage (represented by a cross). Now, copy this image over frames 2 and 3 by creating new key-frames (F6). On Frame 2, position the image a few pixels higher than the other two, as if to give the impression a bullet was fired. It is useful to note here that the cross hair would be much more realistic if you also imported a sound wave onto a new layer at frame 2. There are many sources for these on the Internet, but a good starting point would be www.flashkit.com.

Go back to the main timeline by clicking on the 'Scene 1' link underneath the timeline. Now, drag an instance of your crosshairMC from the library and position it off the left hand side of the stage. Select the MC and name it 'crosshair' in the instance field of the property inspector. Then, open the 'Actions' panel and enter the following:

(ActionScript (AS) for the cross-hair)  
 
onClipEvent(enterFrame) { //When this frame(start)of the  
          //movie is entered place this  
          //MC wherever the mouse is.  
 
this._x = _root._xmouse;  
this._y = _root._ymouse;  
}  
 
//-------------------------------------------------------//

Creating the Bullets

This has to be the easiest part of the whole tutorial. Follow the steps for creating a new symbol as described above. Create a new symbol and name it 'bullet'. Then, when you edit the MC, all you have to do is create a small black bullet hole image on frame 1, using the paintbrush. It doesn't have to be very neat. Select this, make it into a movie clip (F8), and call it 'bullet hole'. Click on frame 30 of the timeline, and press (F5) to fill in all the frames between. Then hit (F6) to make frame 30 a key-frame. With the image on the stage in frame 30 selected, go to the property inspector and change the color to 'Alpha' and '0%'.

Now, right-click in any frame between 1 and 30 on the timeline, and select 'Create Motion Tween'. This will tween the frames so that when the movie clip plays to frame 30, the bullet will slowly disappear. If you don't want this to happen, simply put the bullet image in frame 1, and leave it at that.

Now, create a new layer and name it 'Actions'. Click on frame 30 in the timeline for this layer, and create a new blank key-frame (F7). Select the 'actions' panel and put in a stop action:

stop();

Go back to the main timeline by clicking on the 'Scene 1' link as before, then drag an instance of the bullet off the left hand side of the stage near the cross hair.

Select the bullet instance on the stage, name the instance 'bullet', then enter the following in the actions panel:

(ActionScript (AS) for the bullets)  
 
onClipEvent(mouseDown) {  
 if(!_root.lastFrame) { //if not in the lastFrame  
 i++; //increase the number of i each time so that the  
   //duplicateMCs have a new depth to load to.  
 
 this.duplicateMovieClip(\\\\"bulletnew\\\\", i); //create new  
                  //duplicate  
                  //bulletMC  
   
 _root.crosshair.play(); //play the crosshair movie  
   
 }  
}  
 
onClipEvent(load) { //show bullets wherever mouse is as  
       //each new mc is loaded. Initial bullet  
       //as game loads won't show as it is  
           //hidden in the actions for the    
       //first frame.  
 
 if(!_root.lastFrame) {  
   this._x = _root._xmouse;  
   this._y = _root._ymouse;  
 }  
}  
 
//-------------------------------------------------------//

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links