10. Sound Effects & Music

Series

Determine the beginning of the scene

Firstly, we will add soundtrack music for our game. This music will be played at the beginning of the game. Hence, we have to determine when the scene starts. We are using a built-in condition called “At the beginning of the scene”. So, open the Events tab and add a new event.

 Playing sounds

Create a new action in the previous event. Type play on the search bar, and select Play sound. Add an audio file called “soundtrack.ogg” from the assets folder. Set the volume 40, and enter 1 as the pitch value.

Do not forget to repeat the sound by selecting yes. We are going to loop the soundtrack.

Then, you should see:

Playing sound effects

We will add a laser sound effect that will be played when the player fires a bullet. Go to the FireBegin event. Add a new action to play a sound. Select “sfx_laser.ogg” from the assets folder, set volume to 100, and pitch to 1.

We will add an enemy hit sound effect, which will be played when the player hits the enemy. Go to the Enemies is collision with Bullet event. Add a new action to play a sound. Select “enemy_explosion.waw” from the assets folder, set the volume to 100, and pitch to 1.

Finally, we are going to add a sound effect that will be played when the player collects a powerup. Go to the Player's collision with powerup events. Add a new action to play a sound. Select “sfx_shieldUp.ogg” from the assets folder, set volume to 100, and pitch to 1.

That is all. You can test your sound effects by running the game.

Next step