Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Games with Flutter

You're reading from   Building Games with Flutter The ultimate guide to creating multiplatform games using the Flame engine in Flutter 3

Arrow left icon
Product type Paperback
Published in Jun 2022
Publisher Packt
ISBN-13 9781801816984
Length 224 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Paul Teale Paul Teale
Author Profile Icon Paul Teale
Paul Teale
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1: Game Basics
2. Chapter 1: Getting Started with Flutter Games FREE CHAPTER 3. Chapter 2: Working with the Flame Engine 4. Chapter 3: Building a Game Design 5. Part 2: Graphics and Sound
6. Chapter 4: Drawing and Animating Graphics 7. Chapter 5: Moving the Graphics with Input 8. Chapter 6: Playing Sound Effects and Music 9. Chapter 7: Designing Your Own Levels 10. Chapter 8: Scaling the Game for Web and Desktop 11. Part 3: Advanced Games Programming
12. Chapter 9: Implementing Advanced Graphics Effects 13. Chapter 10: Making Intelligent Enemies with AI 14. Chapter 11: Finishing the Game 15. Other Books You May Enjoy Appendix: Answers

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:

  1. Open the main.dart file. In the onLoad function, where we added the call to play the background music, change this line to pass the volume 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).

  1. Open the george.dart file and let's update the calls to play each sound effect to use the volume parameter. In the onCollision function, update the enemy dying sound effect like this:
    FlameAudio.play('sounds/enemy_dies.wav', volume: 1.0);
  2. In the update function, change the two calls to play the running sound effect, and...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image