SimpleAudioEngine,后台关闭playEffect然后备份

时间:2015-02-23 11:40:24

标签: android cocos2d-x simpleaudioengine

在Cocos2d(android)中我试图在playEffect运行时关闭后台卷,而不是在playEffect结束后将其恢复。我有这段代码:

auto audio = SimpleAudioEngine::getInstance();

audio->playBackgroundMusic("sound/abc-theme.mp3", true);

audio->setBackgroundMusicVolume(0.1);

audio->playEffect("sound/airplane.mp3", false, 1.0f, 1.0f, 1.0f);

audio->setBackgroundMusicVolume(1);

问题是我不知道怎样才能获得playEffect结束,这段代码“立即”将背景音乐设置为1.在PlayEffect的持续时间内,如何将背景音乐的音量调为0.1。

2 个答案:

答案 0 :(得分:1)

auto audio = SimpleAudioEngine::getInstance();

audio->playBackgroundMusic("sound/abc-theme.mp3", true);

audio->setBackgroundMusicVolume(0.1);

audio->playEffect("sound/airplane.mp3", false, 1.0f, 1.0f, 1.0f);

this->scheduleOnce(schedule_selector(LoadingScene::loadingCallBack), 1.0f);

创建一个功能

void ClassName::loadingCallBack(){

 audio->setBackgroundMusicVolume(1);

 }

答案 1 :(得分:0)

我这样做了

 const float Delay=1.0f;
 this->runAction(Sequence::create(DelayTime::create(Delay),CallFunc::create(CC_CALLBACK_0(ABC::bgVolumeUp, this)),nullptr));

和功能

void ABC::bgVolumeUp(){

audio->setBackgroundMusicVolume(1);

}

基本上它与pankaj建议的相似。他给了我这个方法的想法。