To add sound effects to the pirate cove scene, perform the following steps:
Open the
PirateCove.m
file.Update both the
onUpdateDamage
andonUpdateHitpoints
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]; }
Run the example and you will see the following output. We can now hear a sound if we successfully upgrade our pirate ship.