O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fading sounds and music

Taking a queue from Cocos2d actions, CocosDenshion provides a few classes for fading sounds and music. These are CDLongAudioSourceFader and CDXPropertyModifierAction. In this example, we will see how to fade in/out all sounds, individual sounds, and music. We will also see how to crossfade two music sources.

Fading sounds and music

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe.

How to do it...

Execute the following code:

#import "SimpleAudioEngine.h" #import "CDXPropertyModifierAction.h" @implementation Ch6_FadingSoundsAndMusic -(CCLayer*) runRecipe { //Initialize the audio engine sae = [SimpleAudioEngine ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required