A Timeline combines multiple Tweens into one. Its overall behavior is otherwise similar to a single Tween.
The Timeline updates all of its Tweens simultaneously. Its methods allow you to easily build a sequence of Tweens (each one starting after the previous one) or run multiple Tweens at once during given parts of the Timeline.
new Timeline(manager)
name | type | description |
---|---|---|
manager | Phaser.Tweens.TweenManager |
The Tween Manager which owns this Timeline. |
The context in which all callbacks are invoked.
An object containing the different Tween callback functions.
You can either set these in the Tween config, or by calling the Tween.setCallback
method.
onComplete
When the Timeline finishes playback fully or Timeline.stop
is called. Never invoked if timeline is set to repeat infinitely.
onLoop
When a Timeline loops.
onStart
When the Timeline starts playing.
onUpdate
When a Timeline updates a child Tween.
onYoyo
When a Timeline starts a yoyo.
Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes)
Countdown timer value, as used by loopDelay
and completeDelay
.
An array of Tween objects, each containing a unique property and target being tweened.
Time in ms/frames for the whole Timeline to play through once, excluding loop amounts and loop delays.
Elapsed time in ms/frames of this run through of the Timeline.
A constant value which allows this Timeline to be easily identified as one.
Loop this Timeline? Can be -1 for an infinite loop, or an integer. When enabled it will play through ALL Tweens again (use Tween.repeat to loop a single tween)
How many loops are left to run?
Time in ms/frames before this Timeline loops.
The Tween Manager which owns this Timeline.
Does the Timeline start off paused? (if so it needs to be started with Timeline.play)
Value between 0 and 1. The amount of progress through the Timeline, excluding loops.
The current state of the Timeline.
Scales the time applied to this Timeline. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. Value isn't used when calculating total duration of the Timeline, it's a run-time delta adjustment only.
The cached size of the data array.
Time in ms/frames for all Tweens in this Timeline to complete (including looping)
Total elapsed time in ms/frames of the entire Timeline, including looping.
Value between 0 and 1. The amount through the entire Timeline, including looping.
If true then duration, delay, etc values are all frame totals, rather than ms.
Creates a new Tween, based on the given Tween Config, and adds it to this Timeline.
name | type | description |
---|---|---|
config | object | Phaser.Types.Tweens.TweenBuilderConfig |
The configuration object for the Tween. |
This Timeline object.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Calculates the total duration of the timeline.
Computes all tween durations and returns the full duration of the timeline.
The resulting number is stored in the timeline, not as a return value.
Stops all the Tweens in the Timeline immediately, whatever stage of progress they are at and flags them for removal by the TweenManager.
Internal method that will emit a Timeline based Event and invoke the given callback.
name | type | description |
---|---|---|
event | Phaser.Types.Tweens.Event |
The Event to be dispatched. |
callback | function |
The callback to be invoked. Can be |
Calls each of the listeners registered for a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
args | * | <optional> |
Additional arguments that will be passed to the event handler. |
true
if the event had listeners, else false
.
Return an array listing the events for which the emitter has registered listeners.
Parses the relative offset value, returning a positive or negative number.
name | type | description |
---|---|---|
value | string |
The relative offset, in the format of '-=500', for example. The first character determines whether it will be a positive or negative number. Spacing matters here. |
base | number |
The value to use as the offset. |
The parsed offset value.
Gets the value of the time scale applied to this Timeline. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on.
The value of the time scale applied to this Timeline.
Checks whether a Tween has an offset value.
name | type | description |
---|---|---|
tween | Phaser.Tweens.Tween |
The Tween to check. |
true
if the tween has a non-null offset.
Checks if any of the Tweens in this Timeline as operating on the target object.
Returns false
if no Tweens operate on the target object.
name | type | description |
---|---|---|
target | object |
The target to check all Tweens against. |
true
if there is at least a single Tween that operates on the target object, otherwise false
.
Initializes the timeline, which means all Tweens get their init() called, and the total duration will be computed. Returns a boolean indicating whether the timeline is auto-started or not.
true
if the Timeline is started. false
if it is paused.
Checks whether the offset value is a number or a directive that is relative to previous tweens.
name | type | description |
---|---|---|
value | number |
The offset value to be evaluated. |
true
if the result is a number, false
if it is a directive like " -= 1000".
Checks if the offset is a relative value rather than an absolute one. If the value is just a number, this returns false.
name | type | description |
---|---|---|
value | string |
The offset value to be evaluated. |
true
if the value is relative, i.e " -= 1000". If false
, the offset is absolute.
Check whether or not the Timeline is playing.
true
if this Timeline is active, otherwise false
.
Return the number of listeners listening to a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The number of listeners.
Return the listeners registered for a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The registered listeners.
Passed a Tween to the Tween Manager and requests it be made active.
name | type | description |
---|---|---|
tween | Phaser.Tweens.Tween |
The tween object to make active. |
The Timeline's Tween Manager reference.
Updates the Timeline's state
and fires callbacks and events.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Add a one-time listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Pauses the Timeline, retaining its internal state.
Calling this on a Timeline that is already paused has no effect and fires no event.
This Timeline object.
Starts playing the Timeline.
Adds an existing Tween to this Timeline.
name | type | description |
---|---|---|
tween | Phaser.Tweens.Tween |
The Tween to be added to this Timeline. |
This Timeline object.
Remove all listeners, or those of the specified event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol | <optional> |
The event name. |
this
.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Resets all of the timeline's tweens back to their initial states. The boolean parameter indicates whether tweens that are looping should reset as well, or not.
name | type | description |
---|---|---|
resetFromLoop | boolean |
If |
Resumes a paused Timeline from where it was when it was paused.
Calling this on a Timeline that isn't paused has no effect and fires no event.
This Timeline object.
Sets a callback for the Timeline.
name | type | arguments | description |
---|---|---|---|
type | string |
The internal type of callback to set. |
|
callback | function |
Timeline allows multiple tweens to be linked together to create a streaming sequence. |
|
params | array | <optional> |
The parameters to pass to the callback. |
scope | object | <optional> |
The context scope of the callback. |
This Timeline object.
Sets the value of the time scale applied to this Timeline. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on.
The value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only.
name | type | description |
---|---|---|
value | number |
The time scale value to set. |
This Timeline object.
Removes all listeners.
Stops the Timeline immediately, whatever stage of progress it is at and flags it for removal by the TweenManager.
Returns 'true' if this Timeline has finished and should be removed from the Tween Manager. Otherwise, returns false.
name | type | description |
---|---|---|
timestamp | number |
The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. |
delta | number |
The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. |
Returns true
if this Timeline has finished and should be removed from the Tween Manager.