Sound Check: Putting Audio in Your Games

This activity introduces how to put audio into your game.

Turn In: SoundCheck.capx

In this activity we are going incorporate background music, collision sounds, and voice in a Construct2 project. To focus on learning audio, our project will be more a test project rather than a usable game. Use what you learn here to add audio to previous games or future games.

Project Setup

Create a new empty project called SoundCheck.capx with both the layout size and windows size of 800 by 600.

Create a player of your choosing, a paintball, a coin, and an enemy. Insert the keyboard object. Add the 8Direction behavior to the player. Add the Bullet behavior to the paintball.

Duplicate the coin so there are 10 of them and place them around the screen. Duplicate enemy so there are 7 of them and place them around the screen.

On the Event sheet 1 add the following events/actions:

- Event: Keyboard->On Key pressed (space bar) Action: Player->Spawn another object (Paintball)

- Event: Player->On collision with another object (Enemy) Action: Enemy->Destroy

- Event: Paintball->On collision with another object (Enemy) Action: Enemy->Destroy

- Event: Player->On collision with another object (Coin) Action: Coin->Destroy

Run layout and verify that your player can move around, launch paintballs by pressing the space bar, that the paintballs destroy the enemy, and that when the player collides with both coin and enemy the coin/enemy is destroyed. Make any adjustments to make sure your game works as described.

Add the Audio Object

Construct2 has an Audio object that is like the keyboard object ... you add it to the game and shows up in the project listing, does not show up on the layout, but is available when adding events.

Right click on the Layout and pick "Insert new object", find the Media section, select Audio, then click on Insert. You should see Audio in the Object types listing in the Projects area.

Adding Sounds and Sound Events

We are going to add sound effects when a paintball is launch, when a paintball hits an enemy, the player hits an enemy, and the player hits a coin. You will need 4 different sound effects that are a few seconds or shorter in length. For this activity, you can create new sound effects or use ones you have already created. While Construct2 will work with several different formats, one of the preferred formats is WAV so be sure your sound effects are in WAV format.

Note: Construct2 has sound and music. Sounds load completely when the game starts up while music does not load at startup but streams as needed. Short sound effects that we want to play rapidly should go in the Sounds folder and background music should go in the Music folder because we do not want the game to wait until the background music is loaded to start.

In the Projects window (upper right side of Construct2) right click on the Sounds folder and pick "Import Sounds". In the Open box, find the location of your sound effects. You can select one then redo the process for the other three sounds or you can select all four of the sounds you want to import at once. Click on the Open button. Construct2 shows what it is going to import and convert to both Ogg Vorbis and AAC format which will be used to cover all web browsers. If there are any problems with your sounds, you will see a message here. Click on the Import button to finish the process. You will see the details of the import then click on Ok.

In the Sounds folder of the Project window you will have an .m4a and .ogg file for each sound you imported.

Select the Event sheet 1. We are going to add sound effects to several of the events that we created earlier. Find the event where the space is pressed and click on the "Add action" to the right of that event. Select Audio, click Next, pick Play, click Next, select the audio file associated with the launch of a paintball, then click on the Done button.

Run layout and press the space bar a few times. Your sound effect should play. Verify that it sounds ok and works properly.

Follow the same steps for the other three events. "Add action" then pick Audio then select Play and pick the appropriate sound effect.

Run layout and verify that all of your sound effects sound ok and are working properly. If a sound effect is too long, does not sound right, or needs replaced then edit the sound in Audacity and save it. In Construct2, delete both the .m4a and .ogg versions of the sound then import the altered sound effect. You will also need to add the action for that sound effect back in. This can be avoided if you use play by name instead of play.

Adding Music

We are going to add your voice and some background music to the game.

Record yourself saying the following ... "Press the space bar to lauch a paintball. Collide with the coins and enemies to destroy them.". Export that recording to a file of your choosing in WAV format.

In Construct2, right click on the Music folder and pick the voice recording that you just made. Click Open then click Import then click Ok. You should see the voice recording in the Music folder.

On the Event Sheet, add an event ... System->On start of layout. Add action of Audio->Play then pick your voice recording. Run layout and verify the voice recording plays when the game loads.

Finding and Incorporating Background Music

Creating background music for our game is more difficult. For this part of the activity we are going to find some existing background music and incorporate it in our game.

Copyright is very important and needs to be followed in your games. When you create your own sound, graphics, and background music then you own the copyright to the entire game. However, when you use someone elses sound, graphics, or background music then you need their permission to do so or follow the copyright laws on using their work.

Understanding all of the details of copyright can take a long time. We are going to cover it very briefly. Should you decide to sell a game that has someone elses work in it, be sure to research in more detail or ask the person who owns the copyright how to use their work or get their permission to use it.

There are a lot of good sites on the Internet that you can find background music, there are a lot of bad sites that may have viruses or other undesirable things, and there are sites that you can purchase media such as background music.

At the time that this was written, the site below appears to be a legitimate site that can be used to find free background music for a game. Web site do change, disappear, or get purchased by other people. You may find other sites if you like.

Free Music Archive

For this part of the activity, you need to find some background music that you can use in your game. The Free Music Archive and other sites may list the copyright information for a specific item. When you click on one of the Songs on the Free Music Archive site and look on the lower right side of the page, there will be the copyright information ... usually a CC. CC stands for creative commons and has a number of different types of licenses. Some you can use and change, some you can use but not change, some you have to give credit to the author. If you see the CC logo, click on it and will provide more details on that song's specific license. If you see items marked as "Public Domain", those items are available for anyone to use as the author either no longer has rights to the work or has given up those rights.

Once you find the background music that you want to use, if on the Free Music Archive then click on the down arrow to download the file to your computer. Most of the files are in the MP3 format so you will need to convert that to the file to the WAV format for use with Construct2. Open the file in Audacity and export the file in WAV format. Then right click on the Music folder in your Construct2 game and import the background music you just downloaded and converted.

If the license for the music you choose requires attribution (give credit) then add text to your game and give the proper credit. In a real game, most likely there would be a credit screen at the beginning or end of the game to give the owner of the music their proper credit.

Like our voice recording above, we want to play this on start of the layout but we want to loop the background music so it plays for the duration of the game. Here are the steps ...

Beside the On start of layout event, click on Add action. Pick Audio then Next, pick Play then Next. Select the audio file with the background music, set the Loop to "looping", and change the volume from 0 to -5 which will make the background music softer. Run layout and if the background music is too loud change to -10 and if too soft change back to 0.

Please Stop the Music

- Event: Keyboard->On Key pressed (S key) Action: Audio->Stop all

The event above says when the S key is pressed, stop all of the audio (i.e. the background music, voice, or anything else playing). After this event is run, any new sounds or music played will still be audable.

See also the "Set silent" action and some of the others under the Audio object.

Learn More On Your Own: Construct2 has a number of more advanced audio features. In Construct2, click on File then New. In the search box on the upper right of the "Select template or example", type in audio then press Enter. Pick the "Example: Audio effects", run it and review the layout and events. There are a few other examples you can look at as well.

Copyright © 2021 Eric Schumm. Permission granted to freely use this in your classroom.