Cocos2d-x 3.2开发《大富翁》游戏配音

前端之家收集整理的这篇文章主要介绍了Cocos2d-x 3.2开发《大富翁》游戏配音前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、修改AppDelegate.cpp文件

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文件中,大体如下:

7
#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的文件定义

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//交过路费声音
#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"//小本经营概不赊欠
@H_961_403@ #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中

12
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中定义声音播放方法,根据声音开关设置,进行声音的播放

9
Util::playAudioEffect( const char *effectName, bool isLoop)
{
music_on=UserDefault::getInstance()->getBoolForKey(MUSIC_ON_KEY, true );
if (music_on)
{
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(effectName,isLoop);
}
//随机从Vector中取出声音进行播放

10
Util::playAudioEffectRandom(Vector<String*>effectVec,monospace!important; font-size:1em!important; min-height:auto!important; background:none!important">playAudioEffect(effectVec.at( rand ()%effectVec.size())->getCString(),isLoop);
}
Util::stopAudioPlay()
{
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
CocosDenshion::SimpleAudioEngine::getInstance()->stopAllEffects();
4、添加背景音乐,共3首背景音乐,随机播放

14
bgMusicVector.push_back(BG01_MP3);
bgMusicVector.push_back(BG02_MP3);
bgMusicVector.push_back(BG03_MP3);
for ( int i=0;i<bgMusicVector.size();i++)
{
CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic(bgMusicVector.at(i));
}
this ->schedule(schedule_selector(GameBaseScene::playerBgMusic),5.0f);
.....
5、角色对话相关的音效,就是根据具体场景,添加相应的音效播放就可以了

关于音乐音效的比较简单,可以参考:【开发者指南】第十三章:音频

Cocos2d-x之抽奖界面与获奖概率的设计(一)一文中的转盘界面效果做得挺好,稍微修改一下,拿到我们大富翁中来吧。

代码同下一节一并发布。

感谢本系列教程作者李德国分享,Cocos引擎中文官网欢迎开发者分享引擎开发经验。

来源网址:http://www.jb51.cc/article/p-vtuansia-tc.html

原文链接:https://www.f2er.com/cocos2dx/341818.html

猜你在找的Cocos2d-x相关文章