SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
它们的调用一般情况下是在游戏退到后台时调用暂停函数resumeBackgroundMusic(),然后在回到前台时候调用继续函数pauseBackgroundMusic()。这些代码应该放在游戏生命周期函数,如下代码所示。
voidAppDelegate::applicationDidEnterBackground() { Director::getInstance()->stopAnimation(); SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); ① } voidAppDelegate::applicationWillEnterForeground() { Director::getInstance()->startAnimation(); SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); ② }
函数applicationDidEnterBackground是在游戏进入到后台时候回调的函数,在该函数中我们往往需要暂停所有的背景音乐播放(见代码第①行)。而在游戏回到前台时候回调applicationWillEnterForeground,在该函数中我们往往需要继续播放背景音乐(见代码第②行)。
Cocos2d-x中背景音乐播放暂停与继续,布布扣,bubuko.com
原文:http://blog.csdn.net/tonny_guan/article/details/38367909