Skip to content

Commit 9733fb4

Browse files
committed
Updated documentation to clarify 'types' of time
- Added 'Types of time' description and cross-links - Also some general documentation update for Timer - Type specialization Ref phaserjs#2088
1 parent 5af444b commit 9733fb4

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/time/Time.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
*
1313
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
1414
*
15+
* There are different *types* of time in Phaser:
16+
*
17+
* - ***Game time*** always runs at the speed of time in real life.
18+
*
19+
* Unlike wall-clock time, *game time stops when Phaser is paused*.
20+
*
21+
* Game time is used for {@link Phaser.Timer timer events}.
22+
*
23+
* - ***Physics time*** represents the amount of time given to physics calculations.
24+
*
25+
* *When {@link #slowMotion} is in effect physics time runs slower than game time.*
26+
* Like game time, physics time stops when Phaser is paused.
27+
*
28+
* Physics time is used for physics calculations and {@link Phaser.Tween tweens}.
29+
*
30+
* - {@link https://en.wikipedia.org/wiki/Wall-clock_time ***Wall-clock time***} represents the duration between two events in real life time.
31+
*
32+
* This time is independent of Phaser and always progresses, regardless of if Phaser is paused.
33+
*
1534
* @class Phaser.Time
1635
* @constructor
1736
* @param {Phaser.Game} game A reference to the currently running game.

src/time/Timer.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
/**
8-
* A Timer is a way to create small re-usable (or disposable) objects that wait for a specific moment in time,
9-
* and then run the specified callbacks.
8+
* A Timer is a way to create and manage {@link Phaser.TimerEvent timer events} that wait for a specific duration and then run a callback.
9+
* Many different timer events, with individual delays, can be added to the same Timer.
1010
*
11-
* You can add many events to a Timer, each with their own delays. A Timer uses milliseconds as its unit of time (there are 1000 ms in 1 second).
12-
* So a delay to 250 would fire the event every quarter of a second.
11+
* All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second.
1312
*
14-
* Timers are based on real-world (not physics) time, adjusted for game pause durations.
13+
* Timers are based on real life time, adjusted for game pause durations.
14+
* That is, *timer events are based on elapsed {@link Phaser.Time game time}* and do *not* take physics time or slow motion into account.
1515
*
1616
* @class Phaser.Timer
1717
* @constructor
@@ -190,10 +190,10 @@ Phaser.Timer.prototype = {
190190
*
191191
* @method Phaser.Timer#create
192192
* @private
193-
* @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback. This value should be an integer, not a float. Math.round() is applied to it by this method.
193+
* @param {integer} delay - The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
194194
* @param {boolean} loop - Should the event loop or not?
195195
* @param {number} repeatCount - The number of times the event will repeat.
196-
* @param {function} callback - The callback that will be called when the Timer event occurs.
196+
* @param {function} callback - The callback that will be called when the timer event occurs.
197197
* @param {object} callbackContext - The context in which the callback will be called.
198198
* @param {any[]} arguments - The values to be sent to your callback function when it is called.
199199
* @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created.
@@ -234,8 +234,8 @@ Phaser.Timer.prototype = {
234234
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
235235
*
236236
* @method Phaser.Timer#add
237-
* @param {number} delay - The number of milliseconds that should elapse before the callback is invoked.
238-
* @param {function} callback - The callback that will be called when the Timer event occurs.
237+
* @param {integer} delay - The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
238+
* @param {function} callback - The callback that will be called when the timer event occurs.
239239
* @param {object} callbackContext - The context in which the callback will be called.
240240
* @param {...*} arguments - Additional arguments that will be supplied to the callback.
241241
* @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created.
@@ -250,14 +250,15 @@ Phaser.Timer.prototype = {
250250
* Adds a new TimerEvent that will always play through once and then repeat for the given number of iterations.
251251
*
252252
* The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running.
253-
* The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time.
253+
* The delay is in relation to when the Timer starts, not the time it was added.
254+
* If the Timer is already running the delay will be calculated based on the timers current time.
254255
*
255256
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
256257
*
257258
* @method Phaser.Timer#repeat
258-
* @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback.
259+
* @param {integer} delay - The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
259260
* @param {number} repeatCount - The number of times the event will repeat once is has finished playback. A repeatCount of 1 means it will repeat itself once, playing the event twice in total.
260-
* @param {function} callback - The callback that will be called when the Timer event occurs.
261+
* @param {function} callback - The callback that will be called when the timer event occurs.
261262
* @param {object} callbackContext - The context in which the callback will be called.
262263
* @param {...*} arguments - Additional arguments that will be supplied to the callback.
263264
* @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created.
@@ -277,8 +278,8 @@ Phaser.Timer.prototype = {
277278
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
278279
*
279280
* @method Phaser.Timer#loop
280-
* @param {number} delay - The number of milliseconds that should elapse before the Timer will call the given callback.
281-
* @param {function} callback - The callback that will be called when the Timer event occurs.
281+
* @param {integer} delay - The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
282+
* @param {function} callback - The callback that will be called when the timer event occurs.
282283
* @param {object} callbackContext - The context in which the callback will be called.
283284
* @param {...*} arguments - Additional arguments that will be supplied to the callback.
284285
* @return {Phaser.TimerEvent} The Phaser.TimerEvent object that was created.
@@ -292,7 +293,7 @@ Phaser.Timer.prototype = {
292293
/**
293294
* Starts this Timer running.
294295
* @method Phaser.Timer#start
295-
* @param {number} [delay=0] - The number of milliseconds that should elapse before the Timer will start.
296+
* @param {integer} [delay=0] - The number of milliseconds, in {@link Phaser.Time game time}, that should elapse before the Timer will start.
296297
*/
297298
start: function (delay) {
298299

0 commit comments

Comments
 (0)