c++通过dispatchCustomEvent发送事件,通知js层,进入前台和后台

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/84765307
// 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;
}

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/84765307
今日推荐