Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

Enabling and disabling music and sound FX


Now we have music and sound effects working, but we are missing a very important point: allowing the user to disable them. If you add sounds to a game, you need to provide a way to disable them. Many people like to play in silence.

Note

Always provide a way for the user to disable music and sound effects individually.

To do this, we will add two buttons on the main screen (one for music and one for sounds) to enable and disable each one independently. These options should also be present on the Pause dialog, but we will get into that when we rework the dialogs in the next chapter.

On the one hand, we are going to update the layout and the code of MainMenuFragment; on the other hand, we will make SoundManager take care of this configuration.

To store the music and sound state we will use SharedPreferences, as it is the simplest and most convenient way to store key-value persistent data on Android.

Updating MainMenuFragment

Until now, a FrameLayout has been...