This time, we will going to add background music and collision sound effect.
Find the bgm and collision sound and drag them into the your project name folder.
Then you’ll see this screen. Just click finish.
Change the name ‘explosion’, ‘bgMusic’.
Go to GameScene.swift, and let’s add some code. We will import library for audio and video.
And we will create variable for our audio files.
We will set up the audio player and create the path to the audio files.
And we associate the audio variables with their files.
If your music sound is too big, you can change the volume. Mine was okay.
Now we will add collision sound. If the hero get hit, the bgm will stop and only collsion sound will play, and after the countdown the bgm will start again.
And you can also change background color.
And in badguy.swift, we can change the angle or range of motion.
Speed also! These function will going to decide your game’s difficulty.
And I downloaded countdown sound effect. I tried to add a countdown effect. The sound was played well, but didn’t stopped when the game restart. I have to add some code about stop the sound when the game begins.