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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access