Perform the following steps to play background music in our scenes:
Open the
Scene.h
file.Add an instance variable named
backgroundMusic
, which is a pointer toSPSoundChannel
using the following line of code:SPSoundChannel *backgroundMusic;
Declare a method called
stop
as follows:-(void) stop;
Inside the
Scene.m
file, define thestop
method with an empty body.Update the
showScene
method in theSceneDirector.m
file to fit the following block of code:-(void) showScene:(NSString *)name { for (NSString* sceneName in _dict) { ((Scene *) _dict[sceneName]).visible = NO; [((Scene *) _dict[sceneName]) stop]; } if (_dict[name] != nil) { ((Scene *) _dict[name]).visible = YES; [((Scene *) _dict[name]) reset]; } }
Switch to
PirateCove.m
.Inside the initializer, add the following lines at the top:
SPSound *sound = [Assets sound:@"music_cove.aifc"]; backgroundMusic = [sound createChannel]; backgroundMusic...