c++通過dispatchCustomEvent傳送事件,通知js層,進入前臺和後臺
阿新 • • 發佈:2018-12-05
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too void AppDelegate::applicationDidEnterBackground() { auto director = Director::getInstance(); director->stopAnimation(); director->getEventDispatcher()->dispatchCustomEvent("game_on_hide"); #if( CC_PLATFORM_IOS != CC_TARGET_PLATFORM ) SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); SimpleAudioEngine::getInstance()->pauseAllEffects(); #endif } // this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { auto director = Director::getInstance(); director->startAnimation(); director->getEventDispatcher()->dispatchCustomEvent("game_on_show"); #if( CC_PLATFORM_IOS != CC_TARGET_PLATFORM ) SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); SimpleAudioEngine::getInstance()->resumeAllEffects(); #endif }
js層
game_on_hide: function () {
cc.log("-----game_on_hide 遊戲進入後臺");
jsclient.game_on_show = false;
},
game_on_show: function () {
cc.log("-----game_on_show 遊戲進入前臺");
jsclient.game_on_show = true;
}