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 – sound effects in the pirate cove

To add sound effects to the pirate cove scene, perform the following steps:

  1. Open the PirateCove.m file.
  2. Update both the onUpdateDamage and onUpdateHitpoints methods to play a sound effect, as shown in the following code:
    -(void) onUpdateDamage: (SPEvent *) event
    {
        World.damage = World.damage + (int) (World.damage / 10);
        World.gold = World.gold - _goldDamage;
        [self updateGoldTextField];
        
        [[Assets sound:@"powerup.caf"] play];
    }
    
    -(void) onUpdateHitpoints: (SPEvent *) event
    {
        World.hitpoints = World.hitpoints + (int) (World.hitpoints / 5);
        World.gold = World.gold - _goldHitpoints;
        [self updateGoldTextField];
        
        [[Assets sound:@"powerup.caf"] play];
    }
  3. Run the example and you will see the following output. ...

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