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 ...

Get Learning iPhone Game Development with Cocos2D 3.0 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.