主页面音频
??我们已经创建完《保卫萝卜2》主页面上的所有动画(链接:https://blog.csdn.net/qq135595696/article/details/122640221),接下来我们实现主页面音频。
??背景音乐的正确播放时机应该是在场景的构造函数中,这样可以起到“人未到声先到”的过渡效果。即我们应该在MainScene的createScene构造函数中播放对应的背景音乐,代码如下:
cocos2d::Scene* MainScene::createScene()
{
auto mainAudio = SimpleAudioEngine::getInstance();
mainAudio->playBackgroundMusic("Sound/MainMenu/BGMusic.mp3", true);
return MainScene::create();
}
??然后,也给主页面中的“开始冒险”和“天天向上”按钮添加对应的点击音效,代码如下:
_startGameBtn->addTouchEventListener([](Ref* sender, Widget::TouchEventType type) {
switch (type)
{
case ui::Widget::TouchEventType::BEGAN:
{
SimpleAudioEngine::getInstance()->playEffect("Sound/MainMenu/Select.mp3", false, 1.0f, 1.0f, 1.0f);
break;
}
case ui::Widget::TouchEventType::ENDED:
log("_startGameBtn ENDERD");
break;
default:
break;
}
});
_everyDayBtn->addTouchEventListener([](Ref* sender, Widget::TouchEventType type) {
switch (type)
{
case ui::Widget::TouchEventType::BEGAN:
{
SimpleAudioEngine::getInstance()->playEffect("Sound/MainMenu/Unlock.mp3", false, 1.0f, 1.0f, 1.0f);
break;
}
case ui::Widget::TouchEventType::ENDED:
log("_everyDayBtn ENDERD");
break;
default:
break;
}
});
|