HTML and CSS Reference
In-Depth Information
cjs.Sound.alternateExtensions = ['aif', 'webm'];
preload = new cjs.LoadQueue(true, assetsPath);
preload.addEventListener("complete", game.start);
2. Before we have any preloader, we start the game directly in the game.js file.
Now we load the game; the loader will start the game only after all the assets are
loaded. We replace the game.start() method's execuion with game.load()
inside the game.js ile.
3. When the game starts, we play the sound:
game.start = function() {
// existing code goes here."start-game");
4. When the trash buton or the ingredients butons are clicked, we play the following
buton sound:"button");
5. We play the "money-earning" sound when we successfully serve the customer:
if (isEqual) {"earn-money");
// existing code goes here.
6. When we refill the ingredients, we play the refill sound:"refill");
Objective complete - mini debriefing
We have added sound effects to our game. Just as we used to preload the images, we need
to preload the audio files. Therefore, we use PreloadJS to load the audio assets. We start the
game after all the assets are loaded.
We can use the <audio> HTML tag to play the audio. However, an audio library, such as
SoundJS, would provide easier controls and fallbacks in a different technology when web
audio is not available.
Search WWH ::

Custom Search