Cocos2D-X Tutorial: Making a Universal App: Part 2

Learn how to make a universal app that works on the iPhone, iPad, and Android in this Cocos2D-X tutorial. By .

Leave a rating/review
Save for later
Share
You are currently viewing page 2 of 2 of this article. Click here to view the first page.

Gratuitous Sound Effects

As usual, let’s add even more fun to the game with some zany sound effects. Download these sound effects I made with Garage Band and Audacity, unzip the file, and drag the sounds to your Resources folder. Right click on Resources, click Add Files to “WhackAMole”…, make sure that Copy items into destination group’s folder is selected, and click Add.

Then make the following changes to HelloWorldScene.cpp:

// Add to top of file
#include "SimpleAudioEngine.h"

// Add at the bottom of your init function
SimpleAudioEngine::sharedEngine()->preloadEffect("laugh.caf");
SimpleAudioEngine::sharedEngine()->preloadEffect("ow.caf");    SimpleAudioEngine::sharedEngine()->playBackgroundMusic("whack.caf", true);

// Add at the bottom of setTappable
SimpleAudioEngine::sharedEngine()->playEffect("laugh.caf");

// Add inside ccTouchBegan, inside the mole->boundingBox().containsPoint(touchLocation) case 
SimpleAudioEngine::sharedEngine()->playEffect("ow.caf");

Compile and Run your code, and enjoy the groovy tunes!

Where To Go From Here?

Here is a sample project with all of the code you’ve developed so far in this Cocos2D-X tutorial series.

That’s it for this article series (at least for now) – but if you want, why not play with this project some more yourself? I’m sure you can come up with some good ideas for how to make things even better!

Please let me know if you guys still want us to continue releasing Cocos2D-X tutorials, or if you prefer Sprite Kit these days. Your wish is our demand! :]

In the meantime if you have any questions or comments, please join the forum discussion below!