HTML and CSS Reference
In-Depth Information
sounds . push ( tempSound );
To play the sounds, we call playSound() , passing the proper parameters.
The call in eventMouseUp() looks like this:
playSound ( SOUND_SHOOT ,. 5 );
And in drawScreen() , it looks like this:
playSound ( SOUND_EXPLODE ,. 5 );
To display on the canvas how many sounds we have created, we add this code to the
drawScreen() function:
context . fillStyle = "#FFFFFF" ;
context . fillText ( "Active Sounds: " + sounds . length , 200 , 480 );
Now,goaheadandtrythisexample( CH7EX7.html inthecodedistribution). Figure 7-8 shows
what SpaceRaiders iteration#2lookslike.Noticethatwehaveaddedsomedisplaytextatthe
bottom ofthescreen toshowhowmanysoundsareinthesoundsarray.Youwill discover two
issues with this iteration:
1. The sounds play with almost no pauses when loaded from a local drive. But when the
page is loaded from a remote website, there is a defined pause before each sound is
loaded and played.
2. The number of sound objects created is a huge problem. For some browsers, such as
Chrome, the number of active sounds caps out at about 50. After that, no sounds play
at all.
Search WWH ::

Custom Search