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
* @property {number} _lastCount - remember how many 'catch-up' iterations were used on the logicUpdate last frame
304
-
* @private
305
-
*/
314
+
* @property {number} _lastCount - remember how many 'catch-up' iterations were used on the logicUpdate last frame
315
+
* @private
316
+
*/
306
317
this._lastCount=0;
307
318
308
319
/**
309
-
* @property {number} _spiralling - if the 'catch-up' iterations are spiralling out of control, this counter is incremented
310
-
* @private
311
-
*/
320
+
* @property {number} _spiralling - if the 'catch-up' iterations are spiralling out of control, this counter is incremented
321
+
* @private
322
+
*/
312
323
this._spiralling=0;
313
324
314
325
/**
315
-
* @property {Phaser.Signal} fpsProblemNotifier - if the game is struggling to maintain the desiredFps, this signal will be dispatched
316
-
* to suggest that the program adjust it's fps closer to the Time.suggestedFps value
317
-
* @public
318
-
*/
326
+
* If the game is struggling to maintain the desired FPS, this signal will be dispatched.
327
+
* The desired/chosen FPS should probably be closer to the {@link Phaser.Time#suggestedFps} value.
328
+
* @property {Phaser.Signal} fpsProblemNotifier
329
+
* @public
330
+
*/
319
331
this.fpsProblemNotifier=newPhaser.Signal();
320
332
321
333
/**
322
-
* @property {boolean} forceSingleUpdate - Should the game loop force a logic update, regardless of the delta timer? Set to true if you know you need this. You can toggle it on the fly.
323
-
*/
334
+
* @property {boolean} forceSingleUpdate - Should the game loop force a logic update, regardless of the delta timer? Set to true if you know you need this. You can toggle it on the fly.
335
+
*/
324
336
this.forceSingleUpdate=false;
325
337
326
338
/**
327
-
* @property {number} _nextNotification - the soonest game.time.time value that the next fpsProblemNotifier can be dispatched
328
-
* @private
329
-
*/
339
+
* @property {number} _nextNotification - the soonest game.time.time value that the next fpsProblemNotifier can be dispatched
340
+
* @private
341
+
*/
330
342
this._nextFpsNotification=0;
331
343
332
344
// Parse the configuration object (if any)
@@ -710,32 +722,39 @@ Phaser.Game.prototype = {
710
722
711
723
// call the game update logic multiple times if necessary to "catch up" with dropped frames
Copy file name to clipboardExpand all lines: src/time/Time.js
+63-19Lines changed: 63 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -16,55 +16,92 @@ Phaser.Time = function (game) {
16
16
17
17
/**
18
18
* @property {Phaser.Game} game - Local reference to game.
19
+
* @protected
19
20
*/
20
21
this.game=game;
21
22
22
23
/**
23
-
* @property {number} time - This always contains the Date.now value.
24
+
* The `Date.now()` value when the time was last updated.
25
+
* @property {integer} time
24
26
* @protected
25
27
*/
26
28
this.time=0;
27
29
28
30
/**
29
-
* @property {number} prevTime - The time the previous update occurred.
31
+
* The `now` when the previous update occurred.
32
+
* @property {number} prevTime
30
33
* @protected
31
34
*/
32
35
this.prevTime=0;
33
36
34
37
/**
35
-
* @property {number} now - The high resolution RAF timer value (if RAF is available) or Date.now if using setTimeout.
38
+
* An increasing value representing cumulative milliseconds since an undisclosed epoch.
39
+
*
40
+
* This value must _not_ be used with `Date.now()`.
41
+
*
42
+
* The source may either be from a high-res source (eg. if RAF is available) or the standard Date.now;
43
+
* the value can only be relied upon within a particular game instance.
44
+
*
45
+
* @property {number} now
36
46
* @protected
37
47
*/
38
48
this.now=0;
39
49
40
50
/**
41
-
* @property {number} elapsed - Elapsed time since the last frame. In ms if running under setTimeout or an integer if using RAF.
51
+
* Elapsed time since the last time update, in milliseconds, based on `now`.
52
+
*
53
+
* This value _may_ include time that the game is paused/inactive.
54
+
*
55
+
* _Note:_ This is updated only once per game loop - even if multiple logic update steps are done.
56
+
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
57
+
*
58
+
* @property {number} elapsed
42
59
* @see Phaser.Time.time
43
60
* @protected
44
61
*/
45
62
this.elapsed=0;
46
63
47
64
/**
48
-
* @property {number} elapsedMS - The time in ms since the last update. Will vary dramatically based on system performance, do not use for physics calculations!
65
+
* The time in ms since the last time update, in milliseconds, based on `time`.
66
+
*
67
+
* This value is corrected for game pauses and will be "about zero" after a game is resumed.
68
+
*
69
+
* _Note:_ This is updated once per game loop - even if multiple logic update steps are done.
70
+
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
71
+
*
72
+
* @property {integer} elapsedMS
49
73
* @protected
50
74
*/
51
75
this.elapsedMS=0;
52
76
53
77
/**
54
-
* @property {number} pausedTime - Records how long the game has been paused for. Is reset each time the game pauses.
55
-
* @protected
78
+
* The physics update delta, in fractional seconds.
79
+
*
80
+
* This should be used as an applicable multiplier by all logic update steps (eg. `preUpdate/postUpdate/update`)
81
+
* to ensure consistent game timing.
82
+
*
83
+
* With fixed-step updates this normally equivalent to `1.0 / desiredFps`.
84
+
*
85
+
* @property {number} physicsElapsed
56
86
*/
57
-
this.pausedTime=0;
87
+
this.physicsElapsed=0;
58
88
59
89
/**
60
-
* @property {number} desiredFps - The desired frame rate of your game.
90
+
* The desired frame rate of the game.
91
+
*
92
+
* This is used is used to calculate the physic/logic multiplier and how to apply catch-up logic updates.
93
+
*
94
+
* @property {number} desiredFps
61
95
* @default
62
96
*/
63
97
this.desiredFps=60;
64
98
65
99
/**
66
-
* @property {number} suggestedFps = The suggested frame rate for your game, based on an averaged real frame rate.
67
-
* NOTE: Not available until after a few frames have passed, it is recommended to use this after a few seconds (eg. after the menus)
100
+
* The suggested frame rate for your game, based on an averaged real frame rate.
101
+
*
102
+
* _Note:_ This is not available until after a few frames have passed; use it after a few seconds (eg. after the menus)
103
+
*
104
+
* @property {number} suggestedFps
68
105
* @default
69
106
*/
70
107
this.suggestedFps=null;
@@ -109,27 +146,34 @@ Phaser.Time = function (game) {
109
146
this.msMax=0;
110
147
111
148
/**
112
-
* @property {number} physicsElapsed - The physics motion value as used by Arcade Physics. Equivalent to 1.0 / Time.desiredFps.
149
+
* The number of render frames record in the last second. Only calculated if Time.advancedTiming is true.
150
+
* @property {integer} frames
113
151
*/
114
-
this.physicsElapsed=0;
152
+
this.frames=0;
115
153
116
154
/**
117
-
* @property {number} frames - The number of frames record in the last second. Only calculated if Time.advancedTiming is true.
155
+
* The `time` when the game was last paused.
156
+
* @property {number} pausedTime
157
+
* @protected
118
158
*/
119
-
this.frames=0;
159
+
this.pausedTime=0;
120
160
121
161
/**
122
-
* @property {number} pauseDuration - Records how long the game was paused for in miliseconds.
162
+
* Records how long the game was last paused, in miliseconds.
163
+
* (This is not updated until the game is resumed.)
164
+
* @property {number} pauseDuration
123
165
*/
124
166
this.pauseDuration=0;
125
167
126
168
/**
127
169
* @property {number} timeToCall - The value that setTimeout needs to work out when to next update
170
+
* @protected
128
171
*/
129
172
this.timeToCall=0;
130
173
131
174
/**
132
175
* @property {number} timeExpected - The time when the next call is expected when using setTimer to control the update loop
176
+
* @protected
133
177
*/
134
178
this.timeExpected=0;
135
179
@@ -272,13 +316,13 @@ Phaser.Time.prototype = {
272
316
update: function(time){
273
317
274
318
// Set to the old Date.now value
275
-
this.elapsedMS=this.time;
319
+
varpreviousDateNow=this.time;
276
320
277
321
// this.time always holds Date.now, this.now may hold the RAF high resolution time value if RAF is available (otherwise it also holds Date.now)
278
322
this.time=Date.now();
279
323
280
324
// Adjust accorindlgy.
281
-
this.elapsedMS=this.time-this.elapsedMS;
325
+
this.elapsedMS=this.time-previousDateNow;
282
326
283
327
// 'now' is currently still holding the time of the last call, move it into prevTime
0 commit comments