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 music


Background ambient sound is good, but not for our kind of game. What we really need is some music. Let's add the code to play the music, and as we don't want one song playing over and over again, we're going to implement switching between the tracks by performing the following steps:

  1. First of all, we will need some music. Create the group called Music in the Resources group. Then, open the book's supporting files available at Chapter_08/Assets/Music and add all the music files into this group.

    Tip

    You can use your favorite music instead of the music that comes with the book, just name the files the same way or make sure you adjust the code. Also, don't forget about the licenses if you're going to upload the game into the App Store.

  2. Open the AudioManager.h file and import a module using the following @import directive:

    @import AVFoundation.AVAudioPlayer;

    Note

    Note that we're using @import and not #import, as we are importing a module.

  3. Then, make the AudioManager class...