官术网_书友最值得收藏!

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 applicationDidFinishLaunching, 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);

What just happened?

With the preloadEffect method from CocosDenshion, you manage to preload the files as well as instantiate and initialize SimpleAudioEngine. This step will always take a toll on your application's processing power, so it's best to do it early on.

By now, the folder structure for your game should look like this:

What just happened?
主站蜘蛛池模板: 尚志市| 公主岭市| 灵台县| 蓬溪县| 阿拉善盟| 康马县| 凌源市| 崇左市| 西充县| 乌兰察布市| 清苑县| 宁南县| 若羌县| 民勤县| 乌拉特前旗| 乌拉特前旗| 盱眙县| 兴城市| 金秀| 华安县| 盱眙县| 鱼台县| 乐业县| 余姚市| 浙江省| 利津县| 峡江县| 龙海市| 阳原县| 四平市| 正定县| 那曲县| 佛冈县| 阳高县| 恭城| 菏泽市| 娱乐| 开阳县| 湾仔区| 济宁市| 巴南区|