Preloading sounds
Preloading sounds is exactly the same as preloading graphic assets. In the assets
folder, there are two mp3 files: loop.mp3
, which is a short loop used as background music, and bang.mp3
, which is an Uzi sound effect. Remember in your final project, you will have to include the WAV
and OGG
files as well in order to ensure the largest compatibility possible among different browsers in various devices.
The loadassets.js
file will include the array of sounds to preload:
var gameResources = [ "assets/bang.mp3", "assets/loop.mp3" ];
Now, let's create a menu to play with sounds and music.