Controlling the volume
Fixing the volume of the music and sound effects is very easy and only requires a few small changes. Let's take a look:
- Open the
main.dart
file. In theonLoad
function, where we added the call to play the background music, change this line to pass thevolume
parameter:await FlameAudio.bgm.play('music/music.mp3', volume: 0.1);
Here we set the music volume to 0.1
, keeping it low so we can hear the sound effects better. The volume
parameter can be any value between 0.0 and 1.0 (0.0 mutes the sound of the music or sound effect completely, whereas 1.0 plays the sound at full volume).
- Open the
george.dart
file and let's update the calls to play each sound effect to use thevolume
parameter. In theonCollision
function, update the enemy dying sound effect like this:FlameAudio.play('sounds/enemy_dies.wav', volume: 1.0);
- In the
update
function, change the two calls to play the running sound effect, and...