Adding sound effects

Next, we will add the sound effects for the game, but as with the background music, we have to preload the files in advance. So right under where we played the background music in applicationDidFinishLaunching, add the following code to preload files for six sound effects:

CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("enemyKill.wav"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("fireRocket.wav"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("gunshot.wav"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("playerKill.wav"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("pop.wav"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("rocketExplode.wav"); ...

Get Learning Cocos2d-x Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.