Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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, readonly) BOOL isSoundEnabled;
    @property (nonatomic, readonly) BOOL isMusicEnabled;
  3. While still in the AudioManager.h file, add two more method declarations:

    -(void)toggleSound;
    -(void)toggleMusic;
  4. After that, open the AudioManager.m file and...