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 Learning Cocos2d-x Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.