Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
About the Author
About the Reviewers

Playing sound effects and loop background music

Obviously, you wouldn't just want to be loading and unloading your sound effects all day, so let's get into the actual playing of these sounds here.

Getting some background music going

It's always important to set the tone of the voice through the music that gets played in the background. Whether that means a bleak, withering tone or a happy-go-lucky, upbeat tone, the music can help bring in the player so that they become more engaged with the game.

Because the background music will likely be playing for the majority of the time throughout the game, it's not entirely important to preload it. However, it's still recommended, as it will prevent the slight bit of lag at the beginning of the game when the music first starts playing. You can preload the background music using the following code:

[[OALSimpleAudio sharedInstance] preloadBg:@"backgroundMusic.mp3"];

With the preceding line of code added, you can simply play the background music on loop with...