Samsung Galaxy Series error,
cocos2d-html5 version: 2.2.2
After opening a new browser tab, return to the game, not work
Test Environment: Samsung Galaxy note and Samsung Galaxy tab and Samsung Galaxy S
Operating System: Android 4.1.2
Test demo as follows: c.zip, from official demo
Fatal error affected, provide solutions as soon as possible, thank you !
c.zip (3288.8 KB)
First run game, After opening a new browser tab, return to the game, not work
Test demo as follows: a.zip or c.zip, from official demo
Samsung Galaxy Series native browser
Solution:
add code
window.onfocus = function (){
cc.Director.getInstance().resume();
var cocos2dConfig = document['ccConfig'];
var animationInterval = 1/cocos2dConfig['frameRate'];
cc.Director.getInstance().setAnimationInterval(animationInterval);
}
window.onblur = function(){
cc.Director.getInstance().pause();
cc.Director.getInstance().setAnimationInterval(1/10);
}
in main.js
if(cc.Browser.isMobile){
director.setAnimationInterval(1.0 / 50);
}else{
director.setAnimationInterval(1.0 / this.config['frameRate']);
}
Modify application.js
run:function () {
// Initialize instance and cocos2d.
if (!this.applicationDidFinishLaunching())
return 0;
var callback, director = cc.Director.getInstance(), w = window;
cc.director = director;
if (w.requestAnimFrame && this._animationInterval == 1 / 60) {
callback = function () {
director.mainLoop();
w.requestAnimFrame(callback);
};
// cc.log(window.requestAnimFrame);
w.requestAnimFrame(callback);
} else {
var root = this;
callback = function () {
director.mainLoop();
setTimeout(callback, root._animationInterval * 1000);
};
// setInterval(callback, this._animationInterval * 1000);
setTimeout(callback, this._animationInterval * 1000);
}
return 0;
}
});
Hello,
I am getting a similar error. Where I am supposed to write the following code? Many Thanks
window.onfocus = function (){
cc.Director.getInstance().resume();
var cocos2dConfig = document['ccConfig'];
var animationInterval = 1/cocos2dConfig['frameRate'];
cc.Director.getInstance().setAnimationInterval(animationInterval);
}
window.onblur = function(){
cc.Director.getInstance().pause();
cc.Director.getInstance().setAnimationInterval(1/10);
}