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
Time.time used for Date.now but Time.now may hold RAF hi-res value.
Start of separation of game/render update.
Minor adjustments to Time.update for clarity.
Copy file name to clipboardExpand all lines: src/time/Time.js
+25-14Lines changed: 25 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ Phaser.Time = function (game) {
21
21
22
22
/**
23
23
* @property {number} time - Game time counter. If you need a value for in-game calculation please use Phaser.Time.now instead.
24
+
* - This always contains Date.now, but Phaser.Time.now will hold the high resolution RAF timer value (if RAF is available)
24
25
* @protected
25
26
*/
26
27
this.time=0;
@@ -49,6 +50,11 @@ Phaser.Time = function (game) {
49
50
*/
50
51
this.pausedTime=0;
51
52
53
+
/**
54
+
* @property {number} desiredFps = 60 - The desired frame-rate for this project.
55
+
*/
56
+
this.desiredFps=60;
57
+
52
58
/**
53
59
* @property {boolean} advancedTiming - If true Phaser.Time will perform advanced profiling including the fps rate, fps min/max and msMin and msMax.
54
60
* @default
@@ -93,9 +99,10 @@ Phaser.Time = function (game) {
93
99
this.deltaCap=0;
94
100
95
101
/**
96
-
* @property {number} timeCap - If the difference in time between two frame updates exceeds this value, the frame time is reset to avoid huge elapsed counts.
102
+
* @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.
103
+
* - assumes a desiredFps of 60
97
104
*/
98
-
this.timeCap=1/60*1000;
105
+
this.timeCap=1000/60;
99
106
100
107
/**
101
108
* @property {number} frames - The number of frames record in the last second. Only calculated if Time.advancedTiming is true.
@@ -113,9 +120,9 @@ Phaser.Time = function (game) {
113
120
this.timeToCall=0;
114
121
115
122
/**
116
-
* @property {number} lastTime - Internal value used by timeToCall as part of the setTimeout loop
123
+
* @property {number} timeExpected - The time when the next call is expected when using setTimer to control the update loop
117
124
*/
118
-
this.lastTime=0;
125
+
this.timeExpected=0;
119
126
120
127
/**
121
128
* @property {Phaser.Timer} events - This is a Phaser.Timer object bound to the master clock to which you can add timed events.
@@ -242,13 +249,20 @@ Phaser.Time.prototype = {
242
249
*/
243
250
update: function(time){
244
251
245
-
this.prevTime=this.now;
252
+
// 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)
253
+
this.time=Date.now;
246
254
255
+
// 'now' is currently still holding the time of the last call, move it into prevTime
0 commit comments