Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Adding the mute button


In order to keep track of whether the background music has been muted, we will create a user default variable of the bool type, which will help the system remember whether the mute button was pressed the last time or not. If it was muted the last time, the game will pause the music; if not, it will start resuming the music.

To toggle between mute on and off, we will use a new button type named toggle, which will go between the two button states. Let's go ahead and implement it.

First, in the AppDelegate.cpp file, add the following line right before calling the pauseBackgroundMusic() and applicationDidEnterBackground() functions in the resumeBackgroundMusic() and applicationDidEnterForeground functions respectively. This will get the current state of the button from UserDefault. Notice that this time, we are using a boolean variable instead of an int variable, which we have been using to keep track of scores earlier:

bool isPaused = CCUserDefault::sharedUserDefault()-...