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.
Animations, lifespan, particles, physics, timers, and tweens use game time, represented by Phaser.Time#delta and Phaser.Time#deltaTotal. Game time is scaled by Phaser.Time#slowMotion and does not advance when paused.
Input, sounds, and the Scale Manager use clock time, represented by Phaser.Time#time.
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
- Source:
- src/time/Time.js line 26
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 152
-
delta : number
-
The current game step interval in milliseconds.
Type:
- number
- Source:
- src/time/Time.js line 93
-
deltaMax : number
-
The maximum acceptable step interval in milliseconds, based on
desiredMinFps
. You can also set this directly.Type:
- number
- Source:
- src/time/Time.js line 105
-
deltaTotal : number
-
The total of all step intervals in milliseconds.
Type:
- number
- Source:
- src/time/Time.js line 99
-
desiredFps : integer
-
The number of logic updates per second.
This is used is used to calculate Phaser.Time#delta when Phaser.Game#forceSingleUpdate is off.
The render rate is unaffected unless you also turn off Phaser.Game#forceSingleRender.
Type:
- integer
- Default Value:
-
- 60
- Source:
- src/time/Time.js line 606
-
<protected> desiredFpsMult : integer
-
The desired step interval in seconds, based on
desiredFps
.Type:
- integer
- Source:
- src/time/Time.js line 112
-
desiredMinFps : integer
-
The smallest acceptable logic update rate.
This is used is used to calculate Phaser.Time#deltaMax.
It should be substantially smaller than Phaser.Time#desiredFps.
Type:
- integer
- Default Value:
-
- 5
- Source:
- src/time/Time.js line 632
-
<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).
This is updated only once per animation frame, even if multiple logic update steps are done.
Don't use this for game timing. Use delta instead.
Type:
- number
- Source:
- src/time/Time.js line 72
- 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.
This is updated at each logic update, possibly more than once per game loop. If multiple consecutive logic update steps are done,
elapsedMS
will be close to zero after the first.Don't use this for game timing. Use deltaTime instead.
Type:
- integer
- Source:
- src/time/Time.js line 87
-
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 268
-
<readonly> fps : number
-
Advanced timing result: Frames per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 188
-
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 224
-
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 215
-
<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 161
-
<protected> game : Phaser.Game
-
Local reference to game.
Type:
- Source:
- src/time/Time.js line 32
-
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 243
-
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 234
-
<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.
This is updated only once per animation frame, even if multiple logic update steps are done.
Type:
- number
- Source:
- src/time/Time.js line 55
-
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 250
-
<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 179
-
<readonly> rps : number
-
Advanced timing result: Renders per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 206
-
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
Type:
- number
- Default Value:
-
- 1
- Source:
- src/time/Time.js line 145
-
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 133
-
<protected> time : integer
-
The
Date.now()
value when the time was last updated.Type:
- integer
- Source:
- src/time/Time.js line 39
-
<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 262
-
<protected> timeToCall : number
-
The value that setTimeout needs to work out when to next update
Type:
- number
- Source:
- src/time/Time.js line 256
-
<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 170
-
<readonly> ups : number
-
Advanced timing result: Logic updates per second.
Only calculated if advancedTiming is enabled.
Type:
- number
- Source:
- src/time/Time.js line 197
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 323
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 309
-
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 337
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 581
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 569
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 372
-
removeAll()
-
Remove all Timer objects, regardless of their state and clears all Timers from the events timer.
- Source:
- src/time/Time.js line 355
-
reset()
-
Resets the private _started value to now and removes all currently running Timers.
- Source:
- src/time/Time.js line 593
-
totalElapsedSeconds()
-
The number of seconds that have elapsed since the game was started.
- Source:
- src/time/Time.js line 558
Returns:
The number of seconds that have elapsed since the game was started.
- Type
- number
-
<protected> update(time)
-
Updates the game clock and advanced timing data (if enabled) from the given timestamp.
This is called automatically by Phaser.Game once per animation frame (RAF or setTimeout).
Parameters:
Name Type Description time
number The current relative timestamp; see now.
- Source:
- src/time/Time.js line 385