new Time(game)
This is the core internal game clock.
It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens, and also handles the standard Timer pool.
To create a general timed event, use the master Phaser.Timer accessible through events.
There are different types of time in Phaser:
Game time always runs at the speed of time in real life.
Unlike wall-clock time, game time stops when Phaser is paused.
Game time is used for timer events.
Physics time represents the amount of time given to physics calculations.
When slowMotion is in effect physics time runs slower than game time. Like game time, physics time stops when Phaser is paused.
Physics time is used for physics calculations and tweens.
Wall-clock time represents the duration between two events in real life time.
This time is independent of Phaser and always progresses, regardless of if Phaser is paused.
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
- Source:
- src/time/Time.js line 38
Members
-
advancedTiming : boolean
-
If true then advanced profiling, including the fps rate, fps min/max, suggestedFps and msMin/msMax are updated. This isn't expensive, but displaying it with Phaser.Utils.Debug#text can be, especially in WebGL mode.
Type:
- boolean
- Source:
- src/time/Time.js line 173
-
desiredFps : integer
-
The number of logic updates per second.
This is used is used to calculate the physic / logic multiplier and how to apply catch-up logic updates.
The render rate is unaffected unless you also turn off Phaser.Game#forceSingleRender.
Type:
- integer
- Default Value:
-
- 60
- Source:
- src/time/Time.js line 691
-
<protected> desiredFpsMult : integer
-
The desiredFps multiplier as used by Game.update.
Type:
- integer
- Source:
- src/time/Time.js line 129
-
<protected> elapsed : number
-
Elapsed time since the last time update, in milliseconds, based on
now
.This value may include time that the game is paused/inactive.
While the game is active, this will be similar to (1000 / fps).
Note: This is updated only once per game loop - even if multiple logic update steps are done. Use physicsTime as a basis of game/logic calculations instead.
Type:
- number
- Source:
- src/time/Time.js line 89
- See:
-
- Phaser.Time.time
-
<protected> elapsedMS : integer
-
The time in ms since the last time update, in milliseconds, based on
time
.This value is corrected for game pauses and will be "about zero" after a game is resumed.
Note: This is updated once per game loop - even if multiple logic update steps are done. Use physicsTime as a basis of game/logic calculations instead.
Type:
- integer
- Source:
- src/time/Time.js line 102
-
events : Phaser.Timer
-
A Phaser.Timer object bound to the master clock (this Time object) which events can be added to.
Type:
- Source:
- src/time/Time.js line 289
-
<readonly> fps : number
-
Advanced timing result: Frames per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 209
-
fpsMax : number
-
Advanced timing result: The highest rate the fps has reached (usually no higher than 60fps).
Only calculated if advancedTiming is enabled. This value can be manually reset.
Type:
- number
- Source:
- src/time/Time.js line 245
-
fpsMin : number
-
Advanced timing result: The lowest rate the fps has dropped to.
Only calculated if advancedTiming is enabled. This value can be manually reset.
Type:
- number
- Source:
- src/time/Time.js line 236
-
<readonly> frames : integer
-
Advanced timing result: The number of animation frames received from the browser in the last second.
Only calculated if advancedTiming is enabled.
Type:
- integer
- Source:
- src/time/Time.js line 182
-
<protected> game : Phaser.Game
-
Local reference to game.
Type:
- Source:
- src/time/Time.js line 45
-
msMax : number
-
Advanced timing result: The maximum amount of time the game has taken between consecutive frames.
Only calculated if advancedTiming is enabled. This value can be manually reset.
Type:
- number
- Source:
- src/time/Time.js line 264
-
msMin : number
-
Advanced timing result: The minimum amount of time the game has taken between consecutive frames.
Only calculated if advancedTiming is enabled. This value can be manually reset.
Type:
- number
- Default Value:
-
- 1000
- Source:
- src/time/Time.js line 255
-
<protected> now : number
-
An increasing value representing cumulative milliseconds since an undisclosed epoch.
While this value is in milliseconds and can be used to compute time deltas, it must must not be used with
Date.now()
as it may not use the same epoch / starting reference.The source may either be from a high-res source (eg. if RAF is available) or the standard Date.now; the value can only be relied upon within a particular game instance.
Type:
- number
- Source:
- src/time/Time.js line 73
-
pauseDuration : number
-
Records how long the game was last paused, in milliseconds. (This is not updated until the game is resumed.)
Type:
- number
- Source:
- src/time/Time.js line 271
-
physicsElapsed : number
-
The physics update delta, in fractional seconds.
This should be used as an applicable multiplier by all logic update steps (eg.
preUpdate/postUpdate/update
) to ensure consistent game timing. Game/logic timing can drift from real-world time if the system is unable to consistently maintain the desired FPS.With fixed-step updates this is normally equivalent to
1.0 / desiredFps
.Type:
- number
- Source:
- src/time/Time.js line 115
-
physicsElapsedMS : number
-
The physics update delta, in milliseconds - equivalent to
physicsElapsed * 1000
.Type:
- number
- Source:
- src/time/Time.js line 122
-
<protected> prevTime : number
-
The
now
when the previous update occurred.Type:
- number
- Source:
- src/time/Time.js line 59
-
<readonly> renders : integer
-
Advanced timing result: The number of renders made in the last second.
Only calculated if advancedTiming is enabled.
Type:
- integer
- Source:
- src/time/Time.js line 200
-
<readonly> rps : number
-
Advanced timing result: Renders per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 227
-
slowMotion : number
-
Scaling factor to make the game move smoothly in slow motion (or fast motion)
- 1.0 = normal speed
- 2.0 = half speed
- 0.5 = double speed
You likely need to adjust desiredFps as well such that
desiredFps / slowMotion === 60
.Type:
- number
- Default Value:
-
- 1
- Source:
- src/time/Time.js line 166
-
suggestedFps : number
-
The suggested frame rate for your game, based on an averaged real frame rate. This value is only populated if
Time.advancedTiming
is enabled.Note: This is not available until after a few frames have passed; until then it's set to the same value as desiredFps.
Type:
- number
- Source:
- src/time/Time.js line 152
-
<protected> time : integer
-
The
Date.now()
value when the time was last updated.Type:
- integer
- Source:
- src/time/Time.js line 52
-
<protected> timeExpected : number
-
The time when the next call is expected when using setTimer to control the update loop
Type:
- number
- Source:
- src/time/Time.js line 283
-
<protected> timeToCall : number
-
The value that setTimeout needs to work out when to next update
Type:
- number
- Source:
- src/time/Time.js line 277
-
<readonly> updates : integer
-
Advanced timing result: The number of logic updates made in the last second.
Only calculated if advancedTiming is enabled.
Type:
- integer
- Source:
- src/time/Time.js line 191
-
<readonly> ups : number
-
Advanced timing result: Logic updates per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 218
Methods
-
add(timer)
-
Adds an existing Phaser.Timer object to the Timer pool.
Parameters:
Name Type Description timer
Phaser.Timer An existing Phaser.Timer object.
- Source:
- src/time/Time.js line 353
Returns:
The given Phaser.Timer object.
- Type
- Phaser.Timer
-
<protected> boot()
-
Called automatically by Phaser.Game after boot. Should not be called directly.
- Source:
- src/time/Time.js line 337
-
create( [autoDestroy])
-
Creates a new stand-alone Phaser.Timer object.
Parameters:
Name Type Argument Default Description autoDestroy
boolean <optional>
true A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events).
- Source:
- src/time/Time.js line 369
Returns:
The Timer object that was created.
- Type
- Phaser.Timer
-
elapsedSecondsSince(since)
-
How long has passed since the given time (in seconds).
Parameters:
Name Type Description since
number The time you want to measure (in seconds).
- Source:
- src/time/Time.js line 664
Returns:
Duration between given time and now (in seconds).
- Type
- number
-
elapsedSince(since)
-
How long has passed since the given time.
Parameters:
Name Type Description since
number The time you want to measure against.
- Source:
- src/time/Time.js line 652
Returns:
The difference between the given time and now.
- Type
- number
-
refresh()
-
Refreshes the Time.time and Time.elapsedMS properties from the system clock.
- Source:
- src/time/Time.js line 408
-
removeAll()
-
Remove all Timer objects, regardless of their state and clears all Timers from the events timer.
- Source:
- src/time/Time.js line 389
-
reset()
-
Resets the private _started value to now and removes all currently running Timers.
- Source:
- src/time/Time.js line 676
-
totalElapsedSeconds()
-
The number of seconds that have elapsed since the game was started.
- Source:
- src/time/Time.js line 641
Returns:
The number of seconds that have elapsed since the game was started.
- Type
- number
-
<protected> update(time)
-
Updates the game clock and if enabled the advanced timing data. This is called automatically by Phaser.Game.
Parameters:
Name Type Description time
number The current relative timestamp; see now.
- Source:
- src/time/Time.js line 427