Skip to content

Commit ca0a6ae

Browse files
committed
Use rAF instead of setTimeout for 30 fps
1 parent 4dfad9f commit ca0a6ae

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

CCBoot.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ cc.game = /** @lends cc.game# */{
23302330
config[CONFIG_KEY.frameRate] = frameRate;
23312331
if (self._intervalId)
23322332
window.cancelAnimationFrame(self._intervalId);
2333+
self._intervalId = 0;
23332334
self._paused = true;
23342335
self._setAnimFrame();
23352336
self._runMainLoop();
@@ -2512,8 +2513,9 @@ cc.game = /** @lends cc.game# */{
25122513
// @Time ticker section
25132514
_setAnimFrame: function () {
25142515
this._lastTime = new Date();
2515-
this._frameTime = 1000 / cc.game.config[cc.game.CONFIG_KEY.frameRate];
2516-
if ((cc.sys.os === cc.sys.OS_IOS && cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT) || cc.game.config[cc.game.CONFIG_KEY.frameRate] !== 60) {
2516+
var frameRate = cc.game.config[cc.game.CONFIG_KEY.frameRate];
2517+
this._frameTime = 1000 / frameRate;
2518+
if (frameRate !== 60 && frameRate !== 30) {
25172519
window.requestAnimFrame = this._stTime;
25182520
window.cancelAnimationFrame = this._ctTime;
25192521
}
@@ -2551,20 +2553,26 @@ cc.game = /** @lends cc.game# */{
25512553
//Run game.
25522554
_runMainLoop: function () {
25532555
var self = this, callback, config = self.config, CONFIG_KEY = self.CONFIG_KEY,
2554-
director = cc.director;
2556+
director = cc.director,
2557+
skip = true, frameRate = config[CONFIG_KEY.frameRate];
25552558

25562559
director.setDisplayStats(config[CONFIG_KEY.showFPS]);
25572560

25582561
callback = function () {
25592562
if (!self._paused) {
2563+
if (frameRate === 30) {
2564+
if (skip = !skip) {
2565+
self._intervalId = window.requestAnimFrame(callback);
2566+
return;
2567+
}
2568+
}
2569+
25602570
director.mainLoop();
2561-
if (self._intervalId)
2562-
window.cancelAnimationFrame(self._intervalId);
25632571
self._intervalId = window.requestAnimFrame(callback);
25642572
}
25652573
};
25662574

2567-
window.requestAnimFrame(callback);
2575+
self._intervalId = window.requestAnimFrame(callback);
25682576
self._paused = false;
25692577
},
25702578

0 commit comments

Comments
 (0)