You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/time/Time.js
+33-14Lines changed: 33 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,24 @@ Phaser.Time = function (game) {
55
55
*/
56
56
this.desiredFps=60;
57
57
58
+
/**
59
+
* @property {number} suggestedFps = null - The suggested frame-rate for this project.
60
+
* NOTE: not available until after a few frames have passed, it is recommended to use this after a few seconds (eg. after the menus)
61
+
*/
62
+
this.suggestedFps=null;
63
+
64
+
/**
65
+
* @property {number} _frameCount - count the number of calls to time.update since the last suggestedFps was calculated
66
+
* @private
67
+
*/
68
+
this._frameCount=0;
69
+
70
+
/**
71
+
* @property {number} _elapsedAcumulator - sum of the elapsed time since the last suggestedFps was calculated
72
+
* @private
73
+
*/
74
+
this._elapsedAccumulator=0;
75
+
58
76
/**
59
77
* @property {number} slowMotion = 1.0 - Scaling factor to make the game move smoothly in slow motion (1.0 = normal speed, 2.0 = half speed)
60
78
* @type {Number}
@@ -107,6 +125,8 @@ Phaser.Time = function (game) {
107
125
/**
108
126
* @property {number} timeCap - If the difference in time between two frame updates exceeds this value in ms, the frame time is reset to avoid huge elapsed counts.
109
127
* - assumes a desiredFps of 60
128
+
*
129
+
* DEPRECATED: this no longer has any effect since the change to fixed-time stepping in game.update 3rd November 2014
110
130
*/
111
131
this.timeCap=1000/60;
112
132
@@ -270,13 +290,17 @@ Phaser.Time.prototype = {
270
290
// time when the next call is expected if using timers
271
291
this.timeCallExpected=time+this.timeToCall;
272
292
273
-
// spike-dislike
274
-
if(this.elapsed>this.timeCap)
293
+
// count the number of time.update calls
294
+
this._frameCount++;
295
+
this._elapsedAccumulator+=this.elapsed;
296
+
297
+
// occasionally recalculate the suggestedFps based on the accumulated elapsed time
298
+
if(this._frameCount>=this.desiredFps*2)
275
299
{
276
-
// For some reason the time between now and the last time the game was updated was larger than our timeCap
277
-
// This can happen if the Stage.disableVisibilityChange is true and you swap tabs, which makes the raf pause.
278
-
// In this case we'll drop to some default values to stop the game timers going nuts.
279
-
this.elapsed=this.timeCap;
300
+
// this formula calculates suggestedFps in multiples of 5 fps
0 commit comments