Game Development Reference
In-Depth Information
Time for action - adding the sound files
Assuming you have the sound files from the downloaded resources, let's add them to the
project.
1. Drag both the
.wav
files to the
Resources
folder inside your
Project
folder.
2. Then go to Xcode, select the
Resources
folder in the file navigation panel and
select
File
|
Add Files to AirHockey
.
3. Make sure the
AirHockey
target is selected.
4. Go to
AppDelegate.cpp
again. At the top, add this
include
statement:
#include "SimpleAudioEngine.h"
5. Then below the
USING_NS_CC
macro (for
using namespace cocos2d
),
add:
using namespace CocosDenshion;
6. Then just below the lines you added in the previous section, inside
applica-
tionDidFinishLaunching
, add the following lines:
auto audioEngine = SimpleAudioEngine::getInstance();
audioEngine->preloadEffect(
fileUtils->fullPathForFilename("hit.wav").c_str() );
audioEngine->preloadEffect(
fileUtils->fullPathForFilename("score.wav").c_str() );
audioEngine->setBackgroundMusicVolume(0.5f);
audioEngine->setEffectsVolume(0.5f);