Phaser Sounds


What is a game without sounds. Phaser Sounds are very easy to do. Check this video out!

Source Code

Hi!, this is William and today I’m going to show you how to put sounds into your phaser games Now I took our last lesson buttons and I copied it and made it into sounds project folder, and I’ve also put a sounds folder in that sounds folder and with an elephant mp3 file.

You can use any mp3 and all of the source code is on the site WilliamClarkson.net

I’m just going to the change the button green and buttons – blue and I’m going to change that 0,1,0 that we defined for the up over and down frames to 6,7,6 and what that’s doing instead of using the play again and then that will use the start let’s have a look at that.

Great! Now for the sounds, there are three steps to playing a sound in your gain the first one is to load the sound into the library game.load.audio
and then a unique ID such as elephants and the path to the mp3 file sounds/elephant.mp3

the second step is to define our phaser sounds into an object,this.elephantSound for example

this.elephantSound=game.add.audio

and then you give it that unique key that you gave it in the library, elephant,the third and final step is to call play on that object this.elephantSound.play();

so now when we push the button, it will play. so load the sound into the library define it and then play it, those are the three steps

and that is how you put in phaser sounds into your game if you have any questions at all please leave them in the video comments section on youtube, or my facebook page.

I hope that you found this helpful, and thank you for watching

Leave a Reply