Skip to content

Commit

Permalink
modify the calculateDeltaTime
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinCollins committed Apr 4, 2019
1 parent ff386d9 commit 056d9bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions cocos2d/core/CCDirector.js
Expand Up @@ -214,9 +214,8 @@ cc.Director.prototype = {
/**
* calculates delta time since last time it was called
*/
calculateDeltaTime: function () {
var now = performance.now();

calculateDeltaTime: function (now) {
if (!now) now = performance.now();
this._deltaTime = (now - this._lastUpdate) / 1000;
if (CC_DEBUG && (this._deltaTime > 1))
this._deltaTime = 1 / 60.0;
Expand Down Expand Up @@ -925,14 +924,14 @@ cc.Director.prototype = {

this._totalFrames++;

} : function () {
} : function (curTime) {
if (this._purgeDirectorInNextLoop) {
this._purgeDirectorInNextLoop = false;
this.purgeDirector();
}
else if (!this.invalid) {
// calculate "global" dt
this.calculateDeltaTime();
this.calculateDeltaTime(curTime);

// Update
if (!this._paused) {
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/CCGame.js
Expand Up @@ -630,15 +630,15 @@ var game = {

debug.setDisplayStats(config.showFPS);

callback = function () {
callback = function (now) {
if (!self._paused) {
self._intervalId = window.requestAnimFrame(callback);
if (!CC_JSB && !CC_RUNTIME && frameRate === 30) {
if (skip = !skip) {
return;
}
}
director.mainLoop();
director.mainLoop(now);
}
};

Expand Down

0 comments on commit 056d9bc

Please sign in to comment.