Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

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. We can now hear a sound if we successfully upgrade our pirate ship.

What just happened?

Inside the pirate cove scene, we added a sound effect to both the onUpdateDamage and the onUpdateHitpoints methods. We...