From the course: HTML5 Game Development with Phaser
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Adding sound effects
From the course: HTML5 Game Development with Phaser
Adding sound effects
With our game functionality complete, all we need now is to bring more life into the game world, through the inclusion of music and sound effects. So to do this, we need to load in all of our sound effects into preloaded JS. Inside of our Preload function here, I am going to paste in from our code snippets panel, the different pieces of music we want to actually use. So we load, and this time we're loading audio for each of these files. And we're tagging them, so one will be called explosion audio, another one hurt audio, select audio, and game audio. And these simply point to the audio folders, and the particular mp3 file that's associated with each of these sounds. There's one more thing we can do in the preloader to make things a little more solid. And that's in the Update function here. Right now we're just saying red equals true, but something we can do is actually check to make sure that the sound is not only loaded up but is also fully decoded before we run our start menu. So…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.