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 – adding the AudioManager class


We are going to create a simple singleton class and put all the code related to the audio playback into it.

Note

Although we could play any sound effect with just a single line of code by using OALSimpleAudio, we are going to create a special class called AudioManager. This will allow us to keep the audio playback code separate from the rest of our code.

This is a good idea as it allows you to tweak the playback in one place and even switch to some other audio framework without going through all the code and searching and replacing the code. It also decentralizes the access to the audio playback, which means the main screen, game screen, and cut scenes can all control audio.

We will start from almost an empty class, and we will fill it with code as we complete the tasks of adding sound effects and music to our game by performing the following steps:

  1. Open the Cocohunt Xcode project at the point where we left it in the previous chapter.

    Note

    If you...