So You Want to Make a Computer Game: Sound and Music

December 25, 2015

We’ve come a long way from when the series first started. We now have a playable game all the way from start to finish. However, it’s a very quiet game. Today we’ll be adding sound effects and music to polish up the game.

In case you didn’t have a chance to complete the last tutorial you can download my current game project, which will allow you to play through the game from beginning to end, albeit silently.

Free Sounds and Music – The Creative Commons

Throughout this entire blog series we’ve been working to the rule of keeping things as simple as possible while developing our game. Extending that to our sound effects and music, the simplest way to get our audio files is to turn to the internet. Googling “free sound effects” and “free music” will provide numerous sites where you can go to download audio files. Typically these sites will require that you register a user account with them to actually download the files. I recommend spending some time poking around on the different sites first and finding at least one that has sounds and music you think you might use.

Now a few words about “free” audio files before we actually get to the files themselves. Sounds and music that you get off the internet will have been recorded by somebody and the person who recorded them holds the copyright, which means they’re the ones who hold all the rights to how their material can be copied. The basic idea is that you can’t (or at least shouldn’t) copy anything that’s copyrighted without first getting the permission of the copyright holder.

Back in 2001 a new organization called the Creative Commons was formed. Their intent was to encourage copyright holders to make their material available for use under different Creative Commons licenses. People who make their material available under these licenses are basically saying anyone can use them but the licenses will say what usage is permitted. For example, some licenses allow you to do anything you want with the material. Some licenses require that you provide an attribution on who created the material (for example, you might name the person who created the sound effects or music in the credits of your game). Some licenses will indicate that the material cannot be used for commercial purposes, that is, you can’t sell something that makes use of such material. When you download sounds, music, or other Creative Commons material, make sure that you check the Creative Commons license first and understand what you can and can’t do with the material.

File Types

The difficult part of getting audio files off the internet is that there are thousands and thousands and thousands of sounds and music files that you can preview to determine if they’re right for you. As a result, you may have to invest a few hours searching for audio that will work for your game. This can be complicated by the fact that these audio files come in different file formats. Typical formats include things like WAV files, MP3 files, and OGG files.

You need to make sure that you get files that your game creation system will be able to use. For Adventure Maker we can make use of either WAV files or MP3 files. The Adventure Maker website says that OGG files can also be used but this requires an additional download which is no longer available. So we’ll be sticking to WAV and MP3 files.

Now a word about these file formats. You may recall back in the tutorial on creating inventory items that I discussed the differences between lossy and lossless image formats for our artwork. The same terms also apply to audio files.

WAV files are lossless files. They don’t throw away or compress audio in any way. As a result they tend to be very big.

MP3 files are lossy files. Using complex algorithms, they throw away unimportant parts of the sound so that the file size can be much, much smaller. Audio files can become really huge, much larger even than image files. It therefore tends to be better to use a lossy file type, such as MP3, rather than a lossless WAV file.

Sound Effects

All right, now that all the boring legal and technical bits are out of the way, let’s get on to adding sound effects to our game. The first step is to determine what sound effects are needed. For myself, I play through my entire game and write down a list of all the sound effects based on what the player has to do and what they see on screen.

For example, in playing through our game I wrote down the following list of sound effects that I thought it would be good to include:

  • The rattle of moving bones when searching the bone pile.
  • The cocking of a gun when picking up the flintlock pistol.
  • A gunshot sound when shooting the lock off the hatchet.
  • A door opening sound when opening the door down to the underground cave and again when opening the crypt door itself.
  • A door closing sound when the door to the underground cave and the door to the crypt closes.
  • A light switch sound when pulling the string that turns on and off the lights in the crypt.

To save some time, I’ve already pulled together the sound effects that we’ll need for the game in MP3 format. If you’ve been following my tutorials then you should download these sounds to use. If you’ve been doing your own game then you’ll probably have to find sounds of your own.

Licensing

I recorded all of these sounds myself and I’m releasing them under a Creative Commons 0 universal license. This basically means I’m waiving my rights to the copyright on these sounds so you can use them however you want, even in something commercial, without having to pay me a cent, ask my permission, or even attribute the sounds back to me. Because really I can’t be bothered with tracking all the paperwork for that. ;-)

Adding sound effects in Adventure Maker is straightforward. As you may have guessed from looking at the list of sound effects, all of the sound effects will play as the result of the player clicking on specific hotspots within the game.

Let’s start with the pile of bones. First, in Adventure Maker, open up node_26_1, where that pile of bones is. Double-click on the first bones hotspot, the one that shows all the bones, to open its Hotspot Properties window. Here we’ll be using a new tab of the window, the “Audio” tab.

[Set the sound effect played when the bones hotspots are clicked.]
Set the sound effect played when the bones hotspots are clicked.

You’ll see on the audio tab seven “Channel” boxes. This is basically saying that, if you wanted to, you could play up to seven sounds at the same time when the hotspot is clicked. We only need to play one sound effect so we’ll just use the Channel 1 box.

When you click on the Channel 1 box it will give you several options to choose from. We want to use the Play Sound… option, which will then give us the familiar Resources Management window where we can choose the specific sound we want to use. In this case we want to use the “bones_rattle.mp3”. Select that file and then click OK on the Hotspot properties box.

If you preview the frame and click on the first hotspot for the bones pile, you should now hear the sound effect for the rattling bones. All that remains now is to add that same sound effect to the other bone hotspots that need to be clicked on before reaching the flintlock pistol.

As you can see, having sound effects play when the player clicks on a hotspot is a simple thing to do. I’ll leave it to you to add the sound effects to the other places in the game as follows:

  • gun_cocking.mp3 – Play this sound when picking up the flintlock in node_26_1.
  • gunshot.mp3 – Play this sound when using the flintlock on the hatchet in node_27_1. You may want to check the tutorial on inventory items to refresh yourself on how to reach the hotspot properties when using an inventory item on a spot in the frame.
  • door_opening.mp3 – Play this sound when the door opens in node_15_1 and also when the door opens in node_31_1.
  • door_closing.mp3 – Play this sound when the door for node_15_1 gets marked as being closed. Remember that this happens when you click on the left and right hotspots in node_15_1 and it also happens when you click on the middle hotspot in node_28_3.
  • door_closing.mp3 – Play this sound again when the door for node_31_1 gets marked as being closed. Remember that this happens when you click on both the left and right hotspots in node_31_1 itself.
  • door_unlocking.mp3 – Play this sound when using the hatchet on the lock in node_31_1.
  • light_switch.mp3 – Play this sound whenever the player clicks on the light switch hotspot in node_32_1.

Music

Nothing can set the mood of the game better than music. I admire those people who can play and compose their own music because it’s a skill I don’t possess. However, as our discussion on the Creative Commons shows, there are other opportunities available. The key thing, whether using your own music or free music, is to make sure the music is appropriate for your game.

For my games, I like to have complimentary music running in the background most of the time. Other people prefer to use music only in certain situations. The direction you go is up to you.

In looking at our game, I felt there were three areas that could benefit from having their own musical selections:

  • The outdoor park areas where the player is freely moving around.
  • The spooky, claustrophobic cave leading down to the crypt.
  • The interior of the crypt itself where the player encounters the pirate remains and the treasure they’ve been searching for.

I’ve taken the liberty of searching Musopen.com for music to use in each of these areas. Musopen tends to provide mostly classical pieces, which I find work well for more introspective games like the pint-n-click adventure we’re creating here. For a more action oriented game you might want to use more contemporary music.

I’ve prepared a bundle of these three musical selections for download here.

Licensing

These musical selections are all released under a creative commons attribution license, meaning that appropriate credit must be given to the person or people who created them.

For full details, see the Musopen pages for each of these musical pieces:

Adding music to Adventure Maker isn’t any more difficult than adding sound effects. However, we will have to do a few more steps to ensure that music plays properly when the player saves and loads their game. You didn’t know games could be saved and loaded? Well, they can, through the same menu that displays when the player right-clicks to quit the game. But we’ll get to that in a moment.

The first thing we want to do is to edit all the points in the game where the music can change. Here’s a quick rundown of when we want the background music to change:

  • When the game first starts on the “intro” frame we want to start playing the Outside music.
  • When the player moves from the building exterior (node_15_1) to the inside of the cave we want the Cave music to start playing instead.
  • When the player moves from the cave (node_28_3) to the outdoors we want to go back to the Outside music.
  • When the player moves from the crypt door (node_32_1) to the crypt itself we want the Crypt music to start playing instead.
  • When the player moves from the crypt (node_33_1) to the cave we want to go back to the Cave music.

With the exception of the intro frame, all of the music changes occur when the player clicks on hotspots in the game. Let’s get the special one, “intro”, out of the way first.

To start with, go into the “intro” frame. From the menu on the left select Frame Properties… to open the Frame Properties window for the entire frame. On this window you’ll find an Audio tab very similar to the one on the Hotspot Properties window.

[Set the music to start playing and looping in the intro's frame properties.]
Set the music to start playing and looping in the intro's frame properties.

As mentioned above, for this frame we want to use the Outside music (music file Sonata for Cello and Piano - I. Prologue – Lent.mp3). Note that we need to be careful to put the music file into “Channel 2”. This is because we have all of our sound effects playing in channel 1. If we put the music into channel 1 as well, then the music would play until we got to the first sound effect. At that point Adventure Maker would stop the music so that it could play the sound effect on channel 1 instead.

After you’ve chosen the music file, the one other thing you want to do differently here from the sound effects is to check the “Loop” box that appears. Checking this box will cause the music to replay itself automatically after it’s ended. It will keep playing until a different music file starts playing on the same channel from somewhere else in the game.

Now, you’ll want to go to the other four places where our music changes and set the appropriate music tracks there. In these, though, you’ll use the Audio tab of the appropriate hotspots rather than the Audio tab on the Frame Properties itself. Remember that when we set music on the Frame Properties, then it will start playing as soon as the frame is entered but what we want is for the music to start by clicking hotspots (the reason for this will become apparent very shortly).

Once you’ve set up the music in all of the places, you may want to play through the game. Try moving back and forth between the outdoors and the cave and between the cave and the crypt. You should notice that the music changes as you move between the different areas of the game.

This just leaves us with having to keep the music playing when the player saves and loads the game. Go to any node in the game other than the intro screen and save the game. Then reload the game. No music. That’s not good. The reason for this is that, with the exception of the intro screen, we haven’t told Adventure Maker to start playing music on any other frame. We could certainly go through all the frames in our project and set the music for each of them, but (A) we have a lot of frames so that would be really tedious and (B) setting the music on every frame would make it very difficult to change the music in the future if we ever wanted to do that.

Instead we’re going to use what Adventure Maker calls “Resume Locations”. A resume location is nothing more than a special frame that the game goes to when a saved game is first loaded. What we’re going to do is create three of these special frames, one for each of our music tracks, that will start the appropriate piece of music and then immediately change to the actual frame that the player saved their game on. This should become clearer as we work through setting this up.

[Create a blank frame from the main Project Menu.]
Create a blank frame from the main Project Menu.

To start with, make sure you don’t have any frames open so that you can see the Project Menu on the left side of Adventure Maker. Start by clicking the “Create blank frame…” link. This will display a color picker dialog where you can choose the background color for the frame. For our purposes we’ll just go with the default black so you can just click the OK button.

Adventure Maker will ask for a name for the new frame. We’ll use this one to start our first musical selection so let’s call it something like music_1. The name doesn’t really matter, just as long as we can identify it among all our other frames and know what it’s used for.

You should now have a new black frame. Just as you did with the “intro” frame, use this frame’s Frame Properties window to start playing and looping the Outside music in channel 2.

[Set a timer on the music_1 frame to go to the last visited frame.]
Set a timer on the music_1 frame to go to the last visited frame.

While you’re in the Frame Properties window switch back to the General tab. At the bottom of the tab is a section called “Enable Timer” which is used for going to another frame after a certain amount of time has passed on this frame. Check the box for that section to reveal more controls.

Remember that this frame is going to be used when the player loads a game. When that happens, we want this frame to open up, to start the music, and then to immediately switch over to the actual frame that the player saved on. We’ve already got the music ready to go from the Audio tab, now we just need to go to the actual saved frame.

To go to the actual saved frame, open up the dropdown for “Destination frame”. In this case we’re not going to choose a specific frame because the player can save anywhere. Instead we’re going to use the special “Last visited frame” option. This tells Adventure Maker to go to the last frame the player was on before coming to the current frame, or in other words for this case the frame the player saved on.

The last thing we want to do is change the “Interval in seconds”. We don’t want to spend any time on this frame, we just want to go straight through to the frame the player saved on. Adventure Maker won’t let us enter an interval of 0. Instead, the smallest we can enter is “0.001” seconds, which is close enough to 0 as to make no difference to the player.

Using this same set of steps, go ahead and create two more blank frames called music_2 and music_3. They should also go to the Last Visited frame but should start the Cave music and the Crypt music playing and looping on channel 2 respectively.

[Set the resume locations from the main Project Menu.]
Set the resume locations from the main Project Menu.

Almost there, now all we have to do is tell Adventure Maker to use the three blank frames as resume locations. Again close all frames so you can see the Project Menu on the left side of Adventure Maker. This time choose the “Set Resume Locations…” option.

[The Resume Locations window let's you choose what frame the game will start on when reloaded from different locations.]
The Resume Locations window let's you choose what frame the game will start on when reloaded from different locations.

You’ll now be shown the “Resume Locations” window, which lists all of the frames in your game. You’ll see next to each frame is its “Resume Location”. To start with, they all say “-- Same Frame --”. This indicates to Adventure Maker that when a saved game is loaded on a given frame that frame is indeed the one that should be loaded. However, we can change this so that if we saved on frame A we actually load and start on frame B.

As a more concrete example, what we want to do is select all of the outdoor frames and set them to use music_1 as their resume location. That way, if the player loads a game on any of these frames they’ll go to music_1 instead, which will start our first music track playing. Music_1 has been setup to then automatically go to the last frame we were on, which is the actual frame the player saved on. The result? To the player it looks like the game loads on the frame they saved on and they get the music playing.

In the list you can click one frame and then hold down the “Shift” key on your keyboard and click a second frame to select both frames and all the frames in between. You can also hold down the “Ctrl” key on your keyboard and click a frame to add it or remove it from your current selection.

[Set all the outside node to have a resume location of music_1.]
Set all the outside node to have a resume location of music_1.

Once you have at least one frame selected, you can use the “Resume Location” dropdown box on the window to selection the frame that you want to use as the resume location for all of the currently selected frames. Be sure to click the “Assign” button after choosing the resume location to actually set the resume location for all the selected frames.

You’ll want to setup your resume locations as follows:

  • Intro, nodes node_1_1 through node_27_1, and node_35_1 should use music_1. Note: Adventure Maker sorts the frames alphabetically, but doesn’t handle numbers very well so you’ll find, for example, that node_3_1 appears in the list after node_29_4.
  • Node_28_1 through node_32_1 should use music_2.
  • Node_33_1, node_34_1, and outro should use music_3.

Once you’ve made those assignments you can try out the game again. You should now find that when you save and load in different parts of the game that the correct music starts playing again after a load exactly as you’d expect.

With the music all in place, you should take the time to deal with licensing requirements. The three pieces we’re using require that we give attribution to the people that recorded them. I’d suggest making another frame that the “Outro” frame goes to. This new frame can be given an image that lists the credits for the game (be sure to give yourself credit too!). Remember that you’ll have to change the hotspot on the Outro frame to go to this new Credits frame rather than closing the game. And you’ll need to add a new hotspot on the Credits screen that does close the game.

Excellent! We’ve now added sound effects and music to our game. This completes the game itself so we’ve hit a monumental milestone here. Now that we’ve got our game made, we need to package it up for others to enjoy our creativity. We’ll handle that next time, in two weeks. For now, revel in the feeling of having created your first game! A nice Christmas present for yourself.


Read up on the whole “So You Want to Make a Computer Game” series: