HTML and CSS Reference
review that chapter first. In this chapter, we cover only the code necessary to include sound in
Arcade games need to play many sounds simultaneously, and sometimes those sounds play
sounds, solving the problems associated with playing the same sound instance multiple times.
As of this writing, the Opera browser in Windows offers the best support for playing sounds. If you
are having trouble with the sound in this game, any other sound example in the topic, or in your own
games, please test them in the Opera browser.
The sounds for our game
We add three sounds to our game:
▪ A sound for when the player shoots a projectile ( shoot1.mp3 , .ogg , .wav )
▪ A sound for explosions ( explode1.mp3 , .ogg , .wav )
▪ A sound for when the saucer shoots a projectile ( saucershoot.mp3 , .ogg , .wav )
In the file download for this chapter, we have provided each of the three sounds in three
formats: .wav , .ogg , and .mp3 .
Adding sound instances and management variables to the game
var explodeSound ;
var explodeSound2 ;
var explodeSound3 ;
var shootSound ;
var shootSound2 ;
var shootSound3 ;
var saucershootSound ;
var saucershootSound2 ;
var saucershootSound3 ;