O'Reilly logo

Sparrow iOS Game Framework Beginner's Guide by Johannes Stein

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

Time for action – playing music in our scenes

Perform the following steps to play background music in our scenes:

  1. Open the Scene.h file.
  2. Add an instance variable named backgroundMusic, which is a pointer to SPSoundChannel using the following line of code:
    SPSoundChannel *backgroundMusic;
  3. Declare a method called stop as follows:
    -(void) stop;
  4. Inside the Scene.m file, define the stop method with an empty body.
  5. Update the showScene method in the SceneDirector.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]; } } ...

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