cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
7.82k stars 1.89k forks source link

在PC上,监听cc.game.EVENT_HIDE和cc.game.EVENT_SHOW事件会被触发2次? #2839

Closed gyt0412 closed 6 years ago

gyt0412 commented 6 years ago

Creator version?(版本号)

1.9.1

Affected platform?(受影响的平台)

Web

How to reproduce?(如何重现)

1、chrome打开页面:https://abcmouse.qq.com/h5/ 2、F12打开调试面板 3、打开另一个无关页面后,并切换到该页面,再切换回1中打开的页面,看Log,会出现2条 [DcReportAction] onAppReport():pauseApp和[DcReportAction] onAppReport():resumeApp。

Demo project?(demo 项目)

调用代码: onLoad: function () { // 设置为常驻节点 cc.game.addPersistRootNode(this.node);

    cc.game.on(cc.game.EVENT_HIDE, this.onAppPause);
    cc.game.on(cc.game.EVENT_SHOW , this.onAppResume);
    this.onAppStart();//初始化需要自己触发
},

onAppPause:function(){
    cclog.d(TAG,"onAppPause");
    if(!window.GlobalReport.isNative){
        DcReportAction.onAppReport('pauseApp');
    }
},

onAppResume:function(){
    cclog.d(TAG,"onAppResume");
    if(!window.GlobalReport.isNative){
        DcReportAction.onAppReport('resumeApp');
    }
}
jareguo commented 6 years ago

谢谢反馈,这个问题在 1.10 已经修复了。鉴于很多人最近都来反馈,我们会提取到 1.9.3

gyt0412 commented 6 years ago

明白了,谢谢神速回复!