O'Reilly logo

Learning iPhone Game Development with Cocos2D 3.0 by Kirill Muzykov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – toggling sound and music

It is a common task in many games to provide the ON and OFF switch. The most common scenario that I always come across is turning sound and music on and off. We are going to use the same CCButton class to add buttons to the MenuScene class to allow a user to turn the sound and music on and off. To do this, perform the following steps:

  1. Create the group named SoundButtons in the Resources group. Then, open the book supporting files at Chapter_09/Assets/SoundButtons and add the button images to that newly created group.
  2. Open the AudioManager.h file and add the following two properties that we'll use to check if the sound and music is enabled, and set the initial state of the buttons as follows:
    @property (nonatomic, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required