Flixel Adventure Game Tutorial – Part 11: Sound

Index
Previous part: Winning

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:

FlxG.play(sfxBeep);

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.

Next part: Tips

Join the Conversation

4 Comments

  1. I can’t seem to get the sound to work. Everything compiled ok with no errors whatsoever. The audio can be played just fine on pc but not on flash. What could be the problem?

  2. I would be careful about “using music that is […] very old”, but not in the public domain, as in theory you could be sued.

    What you missed to mention is that there is a widespread set of licenses used for royalty free music, called Creative Commons, where you actually should credit the author, but are usually royalty free. Just don’t use NC licensed music if you generate revenue, without getting permission first. Furthermore SA licensed music could also be potentially problematic if your game is is intended to be published with a different license as you don’t want people to build derivative works upon it. See http://stackoverflow.com/questions/8893135/using-cc-by-sa-music-in-a-closed-source-game

    CC licenses music can be found via the CC search
    http://search.creativecommons.org/

    Quite an amount of public domain music can be found at the Public Domain Project that digitizes old records which are in the public domain
    http://pool.publicdomainproject.org/index.php/Main_Page

  3. Hey,this is a crazy good tutorial,it really helped me a lot!!!
    Just wanted to say that I had problems with playing music from the constructor with Flixel 2.55. According to documentation, all initialization should be done in create() function instead of constructor.I’m saying this hoping it will help someone.

Leave a comment

Your email address will not be published. Required fields are marked *