HTML and CSS Reference
In-Depth Information
soundPool . push ({ name : "explode1" , element : explodeSound3 , played : false
false });
soundPool . push ({ name : "shoot1" , element : shootSound , played : false
false });
soundPool . push ({ name : "shoot1" , element : shootSound2 , played : false
false });
soundPool . push ({ name : "shoot1" , element : shootSound3 , played : false
false });
soundPool . push ({ name : "saucershoot" , element : saucershootSound ,
played : false
false });
soundPool . push ({ name : "saucershoot" , element : saucershootSound2 ,
played : false
false });
soundPool . push ({ name : "saucershoot" , element : saucershootSound3 ,
played : false
false });
switchGameState ( GAME_STATE_TITLE )
}
}
In this function, we first remove the event listener from each loaded item and then add the
sounds to our sound pool. Finally, we call the switchGameState() to send the game to the
title screen.
Playing sounds
Soundsplayusingthe playSound() functionfrom Chapter 7 . Wewillnotreprintthatfunction
here, but it is in Example A-2 , where we give the entire set of code for the game. We call
the playSound() function at various instances in our code to play the needed sounds. For ex-
ample, the createExplode() function presented earlier in this chapter included this line:
playSound ( SOUND_EXPLODE ,. 5 );
When we want to play a sound instance from the pool, we call the playSound() function and
pass in the constants representing the sound and the volume for the sound. If an instance of
the sound is available in the pool, it is used, and the sound will play.
Now, let's move on to another type of application pool—the object pool.
Search WWH ::




Custom Search