So you are making your first game, a space invaders type, and you have everything done, except your little spaceship at the bottom of the screen can't shoot the bad aliens that are flying towards him. This tutorial will teach you how to do just that.
Note: This tutorials assumes you are shooting from down to up, if you are shooting from left to right just switch y<->x and height<->width, or if you are going from top to bottom make all the y's negative
To start out we need some symbols:
-a ship sprite (movie clip) and put this on the main timeline and name it.
-a bullet sprite (graphic or movie clip)
-a bullet animation (movie clip)
the bullet needs to be designed in this format: two blank keyframes at the beginning, followed by the bullet sprite starting at (0,0) and then the appropriate number of frames later at (0, -(50 greater than your stage's height) ). Then put a motion tween inbetween the third and last frames so it appears that the bullet is moving.
Then, in frame 1 of the bullet animation, put "stop()" (that is action code: click on the frame and then press F9). Then, in frame 2 of the bullet animation, put the code: "this._x=_root."name"._x" where "name" is replaced with the symbol name you gave your ship on the main timeline.
Then put your bullet animation on the main timeline and give it a symbol name.
Now, click on your ship symbol and add this action code (press F9) within the "onClipEvent(enterFrame) {" parameter (if you don't have this you need to add it and add an end squiggly bracket):
if(Key.isDown(Key.SPACE)) {
_root."name".play()
}
Where "name" is the symbol name you gave your bullet animation. This assumes that you want the space key to fire, if you don't, change "Key.SPACE" to the appropriate key.
I hope that this tutorial has helped you! Please email me if you have any problems and check out my website! Thanks! --Luke
» Level Basic |
Added: 2006-11-07 Rating: 5 Votes: 10 |
» Author |
Has a game website: zazeran.com . Has been using Flash for six months and Java for two years. Please check out his website. |
» Download |
Download the files used in this tutorial. |
Download (0 kb) |
» Forums |
More help? Search our boards for quick answers! |