1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
//Thisfunctionwillbecalledwhentheappisinactive.Whencomesaphonecall,it'sbeinvokedtoo
void
AppDelegate::applicationDidEnterBackground(){
Director::getInstance()->stopAnimation();
//ifyouuseSimpleAudioEngine,itmustbepause
//后台暂停
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
//thisfunctionwillbecalledwhentheappisactiveagain
AppDelegate::applicationWillEnterForeground(){
Director::getInstance()->startAnimation();
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
|
2、在resources 目录下新建sound文件夹,存放游戏声音文件
角色的声音文件定义到ConstUtil.h文件中,大体如下:
#defineP1_DEYIDEYITIAN"sound/byelottery.wav"//拜拜祝您中奖
#defineP1_need1000"sound/need1000.wav"//只要1000元
#defineP1_select_lottery"sound/select_lottery.wav"//请圈选你要购买的彩票
#defineP1_meirendejiang"sound/meirendejiang.wav"//sorry本月份没有人得奖
#defineP1_xiwangshini"sound/xiwangshini.wav"//希望下次得奖者就是您
#defineP1_Speaking_00181"sound/Speaking_00181.wav"//投资获利
#defineP1_Speaking_00182"sound/Speaking_00182.wav"//投资失败
|
//交过路费声音
//抢夺别人地块
//房屋被抢夺
//房屋被摧毁
//摧毁别人房屋
//螃蟹伤人
//看到别人住院
//收取过路费
//升级房子
//不交过路费
//买地
//捡到珍珠
//对方被罚收税
例如:角色1的文件定义
//交过路费声音
#defineP1_Speaking_00435"sound/Speaking_00435.wav"//oh哈利路亚
#defineP1_Speaking_00461"sound/Speaking_00461.wav"//oh我的血汗钱
#defineP1_Speaking_00475"sound/Speaking_00475.wav"//算了算了老子有的是钱
#defineP1_Speaking_01060"sound/Speaking_01060.wav"//老本都快没了
#defineP1_Speaking_001062"sound/Speaking_001062.wav"//拿去了不用找了
//抢夺别人地块
#defineP1_Speaking_00429"sound/Speaking_00429.wav"//让我把他据为己有
//房屋被抢夺
#defineP1_Speaking_00430"sound/Speaking_00430.wav"//黄金地段让给你
#defineP1_Speaking_00464"sound/Speaking_00464.wav"//太不给面子了
#defineP1_Speaking_00469"sound/Speaking_00469.wav"//你皮子痒啊
#defineP1_Speaking_00470"sound/Speaking_00470.wav"//竟敢在太岁头上动土
#defineP1_Speaking_00476"sound/Speaking_00476.wav"//算你狠
//房屋被摧毁
#defineP1_Speaking_00462"sound/Speaking_00462.wav"//好大的胆子
#defineP1_Speaking_00463"sound/Speaking_00463.wav"//谁敢动我的地
#defineP1_Speaking_00466"sound/Speaking_00466.wav"//竟敢破坏我的好事
#defineP1_Speaking_00468"sound/Speaking_00468.wav"//拆的还真干净
#defineP1_Speaking_00474"sound/Speaking_00474.wav"//你有没有搞错啊
#defineP1_Speaking_001061"sound/Speaking_001061.wav"//真没良心
//摧毁别人房屋
#defineP1_Speaking_00433"sound/Speaking_00433.wav"//不必谢我
#defineP1_Speaking_00437"sound/Speaking_00437.wav"//全部夷为平地
//螃蟹伤人
#defineP1_Speaking_00449"sound/Speaking_00449.wav"//快来帮我把
#defineP1_Speaking_01054"sound/Speaking_01054.wav"//我惨了
#defineP1_Speaking_01055"sound/Speaking_01055.wav"//哎呦喂啊
#defineP1_Speaking_001071"sound/Speaking_001071.wav"//我不要打针
//看到别人住院
#defineP1_Speaking_001073"sound/Speaking_001073.wav"//别闹了
//收取过路费
#defineP1_Speaking_00453"sound/Speaking_00453.wav"//小本经营概不赊欠
#defineP1_Speaking_01059"sound/Speaking_01059.wav"//蝇头小利
#defineP1_Speaking_01057"sound/Speaking_01057.wav"//这是我应得的
//升级房子
#defineP1_Speaking_01051"sound/Speaking_01051.wav"//别嫉妒我
#defineP1_Speaking_001066"sound/Speaking_001066.wav"//我真佩服自己
//不交过路费
#defineP1_Speaking_00446"sound/Speaking_00446.wav"//有钱也不给你
#defineP1_Speaking_00477"sound/Speaking_00477.wav"//可别想占我便宜啊
//买地
#defineP1_Speaking_00458"sound/Speaking_00458.wav"//盖什么好呢
#defineP1_Speaking_001067"sound/Speaking_001067.wav"//我是个大地主
//捡到珍珠
#defineP1_Speaking_01052"sound/Speaking_01052.wav"//鸿运当头
#defineP1_Speaking_001063"sound/Speaking_001063.wav"//上帝保佑
//对方被罚收税
#defineP1_Speaking_00452"sound/Speaking_00452.wav"//别想偷漏税
|
3、根据声音的分类把文件名称放入到Vector中,然后根据场景随机从Vector中取出声音进行播放。
在GameBaseScene.cpp的initAudioEffect方法中,据声音的分类把文件名称放入到Vector中
GameBaseScene::initAudioEffect()
{
.........
player2EffectVec_1.pushBack(String::create(P2_SPEAKING01));
player2EffectVec_1.pushBack(String::create(P2_QISIWOLE));
player2EffectVec_1.pushBack(String::create(P2_XINHAOKONGA));
player2EffectVec_1.pushBack(String::create(P2_BUHUIBA));
player2EffectVec_1.pushBack(String::create(P2_PAYHIGH));
player2EffectVec_1.pushBack(String::create(P2_QIANGQIANA));
player2EffectVec_1.pushBack(String::create(P2_HEBAOCHUXIE));
..........
在Util.cpp中定义声音播放方法,根据声音开关设置,进行声音的播放
|