In the previous part we have made a menu and a credits screen, this was all done in complete silence. It’s time to change things for the better by adding some sounds to the mix. There are two types of audio that we will be looking at, sound effects and music.
If you are comfortable creating your own sound effects and/or music, you can make your own with a program like Fruity Loops. If you are like me, you need other people to do it for you. I have some friends who are DJ’s or can play guitar, that I usually ask to make music. You can also use Google to find some royalty free music, that is how I found out about Kevin MacLeod’s music. Another option is using music that is in the public domain and/or very old music like Beethoven’s. Please read this comment for some more legal information.
For sound effects I use a application called as3sfxr, you use it to quickly make unique sound effects. Note that you will have to convert the *.wav file to a *.mp3 file in order to import it.
Let’s add music to the game and a bleep sound when you press the button in the menu, download this bleep and this song, and embed it in the MenuState class. In case you are wondering why the music is so low quality: lower quality means a smaller file size. Note that the songs have relatively large file sizes, so reusing them is a must if you want to keep your game-size small.
[Embed(source = "data/Beep.mp3")] private var sfxBeep:Class; [Embed(source = "data/Music.mp3")] private var sfxMusic:Class;
Flixel has a easy-to-use function for adding music, add the following line to the constructor of the MenuState.
// Play Music FlxG.playMusic(sfxMusic);
Add this to the startGame function:
You can go and add sound effects to any place you like, such as in dialogue or when moving, the sky is the limit! Be careful though, adding to much sounds might be annoying for people when they your game. The next part will be filled with some tips for your adventure game and (Flixel/Flash) programming.
You can download the code for this part here: Flixel Adventure Game Tutorial part 11 code.