Skip to content

10. Sound Effects & Music

Series

You are reading Part 10 of the Space Shooter Tutorial.

  1. Space Shooter, Part 1
  2. Space Shooter, Part 2
  3. Space Shooter, Part 3
  4. Space Shooter, Part 4
  5. Space Shooter, Part 5
  6. Space Shooter, Part 6
  7. Space Shooter, Part 7
  8. Space Shooter, Part 8
  9. Space Shooter, Part 9
  10. Space Shooter, Part 10
  11. Space Shooter, Part 11
  12. Space Shooter, Part 12
  13. Space Shooter, Part 13

Tip

In this chapter, we will learn how to add sound effects and music to our game.

Determine the beginning of the scene

Firstly, we will add soundtrack music to 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.

Warning

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 will 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

Space Shooter, Part 11