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.
Execute the following code:
#import "SimpleAudioEngine.h" #import "CDXPropertyModifierAction.h" @implementation Ch6_FadingSoundsAndMusic -(CCLayer*) runRecipe { //Initialize the audio engine sae = [SimpleAudioEngine sharedEngine]; //Background music is stopped on resign and resumed on becoming active [[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES]; //Initialize source container soundSources = [[NSMutableDictionary alloc] init]; musicSources = [[NSMutableDictionary alloc] init]; //Add music [self loadMusic...