Today we are going to add sound to our games. In the previous tutorial 02 making a simple game we made the beginnings of a game, in the end we were able to catch the squirrel and our score would rise. But the game is very quiet, so it’s time make the squirrel squeak when we click on it.
We use the previous tutorial as base. If you don’t have this one made yourself yet, you can either make it, clone it or or set an image in the editor and work for there.
We start with adding an audio element, which you can find in the element menu in the upper left corner. Don’t forget to give the audio element a name. We called it “ScreamingSquirrel”. You will find out soon enough why that name is suited.
The squirrel has to make a sound at the moment we click on it. To do so, click on the squirrel and add action. Connect the arrow to the sound element and go to the element settings of the arrow. You will see these, when you have selected the connection between the squirrel and the sound element. Set Event on OnClick and action on Play.
Now that we have a connection between the squirrel and the audio element, we still have to add some actual audio. Because we are not sure wat a squirrel sounds like, we choose a screaming cat sound. Afterall the squirrel probably doesn’t like to be clicked.
Click on the audio element that you placed in your game and choose for the first option change audio. In the new menu that opens, you can choose your sound. The cat screaming sound you’ll find in the bundle Tutorial. In this menu you can listen to a demo of the sound, before adding it. Click on the image of the sound file to add it in your game.
Time for testing, catch the squirrel and hear its new sound.
Well done! Now you know how to add some sound in your game. Please show us your creations, we would love see them. You can share the link in our community.