Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify the calculateDeltaTime #4152

Merged
merged 1 commit into from Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 (now) {
if (this._purgeDirectorInNextLoop) {
this._purgeDirectorInNextLoop = false;
this.purgeDirector();
}
else if (!this.invalid) {
// calculate "global" dt
this.calculateDeltaTime();
this.calculateDeltaTime(now);

// 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