- Cocos2d-x by Example:Beginner's Guide(Second Edition)
- Roger Engelbert
- 174字
- 2021-07-23 20:00:28
Time for action – adding the sound files
Assuming you have the sound files from the downloaded resources, let's add them to the project.
- Drag both the
.wav
files to theResources
folder inside yourProject
folder. - Then go to Xcode, select the
Resources
folder in the file navigation panel and select File | Add Files to AirHockey. - Make sure the AirHockey target is selected.
- Go to
AppDelegate.cpp
again. At the top, add thisinclude
statement:#include "SimpleAudioEngine.h"
- Then below the
USING_NS_CC
macro (forusing namespace cocos2d
), add:using namespace CocosDenshion;
- 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:

推薦閱讀
- UI圖標(biāo)創(chuàng)意設(shè)計(jì)
- 兩周自制腳本語言
- Vue.js 2 and Bootstrap 4 Web Development
- C語言程序設(shè)計(jì)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Java程序員面試筆試寶典(第2版)
- Citrix XenServer企業(yè)運(yùn)維實(shí)戰(zhàn)
- Programming Microsoft Dynamics? NAV 2015
- Arduino Wearable Projects
- 硬件產(chǎn)品設(shè)計(jì)與開發(fā):從原型到交付
- Node.js從入門到精通
- 監(jiān)控的藝術(shù):云原生時(shí)代的監(jiān)控框架
- Microsoft HoloLens By Example
- Python機(jī)器學(xué)習(xí)開發(fā)實(shí)戰(zhàn)
- Selenium Essentials