O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

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

Adding audio effects

To add audio effects, we will first add a simple click sound that will tell us that a button has been pressed. Then, we will add some audio effects to the main game.

Getting ready

Import the click.mp3 file from the resources folder for the chapter.

How to do it…

We will modify playBtnPressed and optionsBtnPressed as follows:

-(void)playBtnPressed:(id)sender{ CCLOG(@"play button pressed"); OALSimpleAudio *audio = [OALSimpleAudio sharedInstance]; [audio playEffect:@"click.mp3" loop:NO]; //[[CCDirector sharedDirector] replaceScene:[[GameplayScene alloc] initWithLevel:@"1"]]; CCTransition *transition = [CCTransition transitionRevealWithDirection:CCTransitionDirectionLeft duration:0.2]; [[CCDirector sharedDirector]replaceScene:[[GameplayScene ...

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