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
Clock.addEvent can now take an existing TimerEvent object, as well as a config object. If a TimerEvent is given it will be removed from the Clock, reset and then added. This allows you to pool TimerEvents rather than constantly create and delete them. Fixphaserjs#4115
`Clock.removeEvent` is a new method that allows you to remove a `TimerEvent`, or an array of them, from all internal lists of the current Clock.
Copy file name to clipboardExpand all lines: src/time/Clock.js
+62-12Lines changed: 62 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ var Class = require('../utils/Class');
8
8
varPluginCache=require('../plugins/PluginCache');
9
9
varSceneEvents=require('../scene/events');
10
10
varTimerEvent=require('./TimerEvent');
11
+
varRemove=require('../utils/array/Remove');
11
12
12
13
/**
13
14
* @classdesc
@@ -55,12 +56,9 @@ var Clock = new Class({
55
56
*/
56
57
this.now=0;
57
58
58
-
// Scale the delta time coming into the Clock by this factor
59
-
// which then influences anything using this Clock for calculations, like TimerEvents
60
-
61
59
/**
62
60
* The scale of the Clock's time delta.
63
-
*
61
+
*
64
62
* The time delta is the time elapsed between two consecutive frames and influences the speed of time for this Clock and anything which uses it, such as its Timer Events. Values higher than 1 increase the speed of time, while values smaller than 1 decrease it. A value of 0 freezes time and is effectively equivalent to pausing the Clock.
65
63
*
66
64
* @name Phaser.Time.Clock#timeScale
@@ -94,7 +92,7 @@ var Clock = new Class({
94
92
this._active=[];
95
93
96
94
/**
97
-
* An array of all Timer Events which will be added to the Clock at the start of the frame.
95
+
* An array of all Timer Events which will be added to the Clock at the start of the next frame.
98
96
*
99
97
* @name Phaser.Time.Clock#_pendingInsertion
100
98
* @type {Phaser.Time.TimerEvent[]}
@@ -105,7 +103,7 @@ var Clock = new Class({
105
103
this._pendingInsertion=[];
106
104
107
105
/**
108
-
* An array of all Timer Events which will be removed from the Clock at the start of the frame.
106
+
* An array of all Timer Events which will be removed from the Clock at the start of the next frame.
* Creates a Timer Event and adds it to the Clock at the start of the frame.
158
156
*
157
+
* You can also pass in an existing Timer Event, which will be reset and added to this Clock.
158
+
*
159
+
* Note that if the Timer Event is being used by _another_ Clock (in another Scene) it will still
160
+
* be updated by that Clock as well, so be careful when using this feature.
161
+
*
159
162
* @method Phaser.Time.Clock#addEvent
160
163
* @since 3.0.0
161
164
*
162
-
* @param {Phaser.Types.Time.TimerEventConfig} config - The configuration for the Timer Event.
165
+
* @param {(Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig)} config - The configuration for the Timer Event, or an existing Timer Event object.
163
166
*
164
-
* @return {Phaser.Time.TimerEvent} The Timer Event which was created.
167
+
* @return {Phaser.Time.TimerEvent} The Timer Event which was created, or passed in.
0 commit comments