Game pause when change tabs or minium browser

Game pause when change tabs or minium browser
0.0 0

#1

When I change tabs web or minium browser , game will pause and It will run continus when I open game tabs. but I want it run even change tabs or miniun browser. someone help me please. thanks!


#2

Cocos2d-html5 use requestAnimFrame for main loop. It will automatically pause the update/draw.

So, if you want your game keeping running, you should switch requestAnimFrame to setInterval, and disable the audio pausing.
Please refer to /cocos2d-html5/cocos2d/core/platform/CCApplication.js line 375 and line 258.


#3

Thanks ShunLin, sound is good, I changed function like this but It still not run when change tabs or minium:

run:function () {
// Initialize instance and cocos2d.
if (!this.applicationDidFinishLaunching()) return 0;
var callback, director = cc.Director.getInstance(), w = window;
cc.director = director;
callback = function () {
director.mainLoop();
};
setInterval(callback, this._animationInterval * 1000);
return 0;
}


#4

How to do that in cocos2d html5 v3.8 ?


#5

How to do that in cocos2d html5 v3.10? :frowning:


#6

Check CCBoot.js line no - 2480.
frame rate config check is there if frame rate is not 60.


#7

Line no 2713 in CCBoot.js

Comment these line if you want your game to run even if tab is changed.

    var onHidden = function () {
        /*if (cc.eventManager && cc.game._eventHide)
            cc.eventManager.dispatchEvent(cc.game._eventHide);*/
    };
    var onShow = function () {
        /*if (cc.eventManager && cc.game._eventShow)
            cc.eventManager.dispatchEvent(cc.game._eventShow);*/
    };

#8

Music keeps playing if I leave cocos js window open and go editing code for example , how do I solve that ?
Chromium on Ubuntu linux .