• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Space Shooter - Game Pause and Sound

Category : Flash Views : 60328
Version : 8 Rating : 
3.1/5 (112 votes)
  • Currently 3.06/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: space-shooter-pause-game-sound.zip
Result: See the result


<<< PreviousIndex Series

Previous | 1 | 2 | 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 last part of our game and we are going to add sound and a pause key.

Before we start with sound we need to make some changes. You may have noticed that our ship shoots bullets as much as the player press the space bar, that's not right as it makes the game much easier.
To prevent that, we are going to add a timer and the ship will shoot as much as WE want.
First add a new variable:
var timer = 8;

Now make these changes:
this.onEnterFrame = function() { timer++; . . . if (Key.isDown(Key.SPACE)) { i++; if(timer >= 8) { _root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth()); _root["Bullet" + i]._x = Ship._x + 3; _root["Bullet" + i]._y = Ship._y; timer = 0; } } }

The code runs like this:
1. If timer >= 8 then shoot a bullet and set timer to 0
2. Now that timer = 0, the bullet wont shoot, so the player has to wait all the code to run at least 8 timer to shoot again (timer++ will increase timer by 1 every frame)
3. Timer will be bigger than 8 again and the player can shoot.

Before:
Free Flash Tutorials, Free Flash Game, Space Shooter Game, Pause Game and Sound

After:
Free Flash Tutorials, Free Flash Game, Space Shooter Game, Pause Game and Sound

We can add the sound now. You need to have an mp3 file that's going to be the sound played when you fire. You can download one right here. Or simply download the source file that contains sound file.

Now that you have your sound, click File > Import > Import to library...
Select your mp3 file and click open, a new file should appear on the library. Right click it and click "Linkage..."
Check "Export to Actionscript..." and set the Identifier to "shoot".
This is the same thing we did previously with the Bullet Movie Clip, we need the linkage to call this on the code.

Add this to the shooting code:
if (Key.isDown(Key.SPACE)) { i++; if(timer >= 8) { _root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth()); _root["Bullet" + i]._x = Ship._x + 3; _root["Bullet" + i]._y = Ship._y; var shoot_sound = new Sound(); shoot_sound.attachSound("shoot"); shoot_sound.start(); timer = 0; } }


del.icio.us digg it Reddit Stumble Upon Technorati

Previous | 1 | 2 | Next

<<< PreviousIndex Series
How to Video Tutorials on software by Helpvids.com

Video tutorial: Forex trading



Sponsors



Advertisement









Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.