• 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 : 60306
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

The first thing we do is declare a new Sound():
var shoot_sound = new Sound();

Then we attach the sound we have on our library to this variable:
shoot_sound.attachSound("shoot");

And we tell our sound to play using the start() method:
shoot_sound.start();

Run the code (Ctrl + Enter) and see the results.

Now we are going to add a pause to our game.
Add a new variable to know whether we are paused or not:
var gpause = false;

Then make some changes to ALL codes.
Main code:
this.onEnterFrame = function() { if (!gpause) { //this is the rest of the code we did previously. } }

Enemy's code:
onClipEvent(enterFrame) { if (!_root.gpause) { this._x -= mySpeed; if (this._x < -10) { reset(); } } }

Bullet's code:
this.onEnterFrame = function() { if (!_root.gpause) { //rest of the code we did } }

It's pretty simple; if gpause is false the code will run normally, but if gpause is true the code will not run.

Add another code to the main timeline:
this.onEnterFrame = function() { if (!_root.gpause) { //rest of the code we did } if (Key.isDown(Key.CONTROL)) { if (gpause) { gpause = false; } else if (!gpause) { gpause = true; } } }

If the players press "ctrl" we set gpause to true or false depending on the value of gpause.
This needs to be outside "if (!_root.gpause)" because we need to check if the user pressed the pause key even if the game is paused.

The game is done! I hope you enjoyed developing it. And see you in the next series!


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.