Adding looped background music

Cocos2d-x has a separate engine for the sound named CocosDenshion and uses the SimpleAudioEngine.h header. Whenever you want to include calls for any of its function, you will have to include this header. Similar to the CCDirector class, the Simple Audio Engine is also a singleton class that you will use to start, pause, resume, and stop a particular background sound or effect.

As you would have noticed, there are two types of audio in games—background music, which lasts for about usually 30 seconds to a minute and gets looped over time, and there are sound effects that get played when a certain event occurs, such as shooting a bullet or enemy getting hurt and it lasts a couple of seconds. Both files are called separately ...

Get Learning Cocos2d-x Game Development 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.