As the name implies, this is the base Tween class that both the Tween and TweenChain inherit from. It contains shared properties and methods common to both types of Tween.
Typically you would never instantiate this class directly, although you could certainly use it to create your own variation of Tweens from.
new BaseTween(parent)
name | type | description |
---|---|---|
parent | Phaser.Tweens.TweenManager | Phaser.Tweens.TweenChain |
A reference to the Tween Manager, or Tween Chain, that owns this Tween. |
The scope (or context) in which all of the callbacks are invoked.
This defaults to be this Tween, but you can override this property to set it to whatever object you require.
An object containing the different Tween callback functions.
You can either set these in the Tween config, or by calling the Tween.setCallback
method.
The types available are:
onActive
- When the Tween is first created it moves to an 'active' state when added to the Tween Manager. 'Active' does not mean 'playing'.
onStart
- When the Tween starts playing after a delayed or paused state. This will happen at the same time as onActive
if the tween has no delay and isn't paused.
onLoop
- When a Tween loops, if it has been set to do so. This happens after the loopDelay
expires, if set.
onComplete
- When the Tween finishes playback fully. Never invoked if the Tween is set to repeat infinitely.
onStop
- Invoked only if the Tween.stop
method is called.
onPause
- Invoked only if the Tween.pause
method is called. Not invoked if the Tween Manager is paused.
onResume
- Invoked only if the Tween.resume
method is called. Not invoked if the Tween Manager is resumed.
The following types are also available and are invoked on a TweenData
level - that is per-object, per-property, being tweened.
onYoyo
- When a TweenData starts a yoyo. This happens after the hold
delay expires, if set.
onRepeat
- When a TweenData repeats playback. This happens after the repeatDelay
expires, if set.
onUpdate
- When a TweenData updates a property on a source target during playback.
The time in milliseconds before the 'onComplete' event fires.
This never fires if loop = -1
as it never completes because it has been
set to loop forever.
An internal countdown timer (used by loopDelay and completeDelay)
The main data array. For a Tween, this contains all of the TweenData
objects, each
containing a unique property and target that is being tweened.
For a TweenChain, this contains an array of Tween
instances, which are being played
through in sequence.
Has this Tween started playback yet?
This boolean is toggled when the Tween leaves the 'start delayed' state and begins running.
The number of times this Tween will loop.
Can be -1 for an infinite loop, zero for none, or a positive integer.
Typically this is set in the configuration object, but can also be set directly as long as this Tween is paused and hasn't started playback.
When enabled it will play through ALL Tweens again.
Use TweenData.repeat to loop a single element.
Internal counter recording how many loops are left to run.
The time in milliseconds before the Tween loops.
Only used if loop
is > 0.
A reference to the Tween Manager, or Tween Chain, that owns this Tween.
Is the Tween currently paused?
A paused Tween needs to be started with the play
method, or resumed with the resume
method.
This property can be toggled at runtime if required.
Will this Tween persist after playback? A Tween that persists will not be destroyed by the
Tween Manager, or when calling Tween.stop
, and can be re-played as required. You can either
set this property when creating the tween in the tween config, or set it prior to playback.
However, it's up to you to ensure you destroy persistent tweens when you are finished with them, or they will retain references you may no longer require and waste memory.
By default, Tweens
are set to not persist, so they are automatically cleaned-up by
the Tween Manager.
The time in milliseconds before the 'onStart' event fires.
For a Tween, this is the shortest delay
value across all of the TweenDatas it owns.
For a TweenChain, it is whatever delay value was given in the configuration.
Scales the time applied to this Tween. 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.
This value is multiplied by the TweenManager.timeScale
.
The cached size of the data array.
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
.
Flags the Tween as being complete, whatever stage of progress it is at.
If an onComplete
callback has been defined it will automatically invoke it, unless a delay
argument is provided, in which case the Tween will delay for that period of time before calling the callback.
If you don't need a delay or don't have an onComplete
callback then call Tween.stop
instead.
name | type | arguments | description |
---|---|---|---|
delay | number | <optional> |
The time to wait before invoking the complete callback. If zero it will fire immediately. |
This Tween instance.
Flags the Tween as being complete only once the current loop has finished.
This is a useful way to stop an infinitely looping tween once a complete cycle is over, rather than abruptly.
If you don't have a loop then call Tween.stop
instead.
name | type | arguments | description |
---|---|---|---|
loops | number | <optional> |
The number of loops that should finish before this tween completes. Zero means complete just the current loop. |
This Tween instance.
Handles the destroy process of this Tween, clearing out the Tween Data and resetting the targets. A Tween that has been destroyed cannot ever be played or used again.
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.
Gets the value of the time scale applied to this Tween. 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 Tween.
Returns true
if this Tween has a current state of ACTIVE, otherwise false
.
true
if this Tween has a current state of ACTIVE, otherwise false
.
Returns true
if this Tween has a current state of COMPLETE_DELAY, otherwise false
.
true
if this Tween has a current state of COMPLETE_DELAY, otherwise false
.
Returns true
if this Tween has a current state of DESTROYED, otherwise false
.
true
if this Tween has a current state of DESTROYED, otherwise false
.
Returns true
if this Tween has a current state of FINISHED, otherwise false
.
true
if this Tween has a current state of FINISHED, otherwise false
.
Returns true
if this Tween has a current state of LOOP_DELAY, otherwise false
.
true
if this Tween has a current state of LOOP_DELAY, otherwise false
.
Checks if the Tween is currently paused.
This is the same as inspecting the BaseTween.paused
property directly.
true
if the Tween is paused, otherwise false
.
Returns true
if this Tween has a current state of PENDING, otherwise false
.
true
if this Tween has a current state of PENDING, otherwise false
.
Returns true
if this Tween has a current state of PENDING_REMOVE, otherwise false
.
true
if this Tween has a current state of PENDING_REMOVE, otherwise false
.
Checks if this Tween is currently playing.
If this Tween is paused, or not active, this method will return false.
true
if the Tween is playing, otherwise false
.
Returns true
if this Tween has a current state of REMOVED, otherwise false
.
true
if this Tween has a current state of REMOVED, otherwise false
.
Returns true
if this Tween has a current state of START_DELAY, otherwise false
.
true
if this Tween has a current state of START_DELAY, 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.
Internal method that makes this Tween active within the TweenManager and emits the onActive event and callback.
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
.
Internal method that handles this tween completing and emitting the onComplete event and callback.
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 Tween immediately. Use resume
to continue playback.
You can also toggle the Tween.paused
boolean property, but doing so will not trigger the PAUSE event.
This Tween instance.
Immediately removes this Tween from the TweenManager and all of its internal arrays,
no matter what stage it is at. Then sets the tween state to REMOVED
.
You should dispose of your reference to this tween after calling this method, to
free it from memory. If you no longer require it, call Tween.destroy()
on it.
This Tween instance.
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
.
Resumes the playback of a previously paused Tween.
You can also toggle the Tween.paused
boolean property, but doing so will not trigger the RESUME event.
This Tween instance.
Sets this Tween state to ACTIVE.
Sets an event based callback to be invoked during playback.
Calling this method will replace a previously set callback for the given type, if any exists.
The types available are:
onActive
- When the Tween is first created it moves to an 'active' state when added to the Tween Manager. 'Active' does not mean 'playing'.
onStart
- When the Tween starts playing after a delayed or paused state. This will happen at the same time as onActive
if the tween has no delay and isn't paused.
onLoop
- When a Tween loops, if it has been set to do so. This happens after the loopDelay
expires, if set.
onComplete
- When the Tween finishes playback fully. Never invoked if the Tween is set to repeat infinitely.
onStop
- Invoked only if the Tween.stop
method is called.
onPause
- Invoked only if the Tween.pause
method is called. Not invoked if the Tween Manager is paused.
onResume
- Invoked only if the Tween.resume
method is called. Not invoked if the Tween Manager is resumed.
The following types are also available and are invoked on a TweenData
level - that is per-object, per-property, being tweened.
onYoyo
- When a TweenData starts a yoyo. This happens after the hold
delay expires, if set.
onRepeat
- When a TweenData repeats playback. This happens after the repeatDelay
expires, if set.
onUpdate
- When a TweenData updates a property on a source target during playback.
name | type | arguments | description |
---|---|---|---|
type | Phaser.Types.Tweens.TweenCallbackTypes |
The type of callback to set. One of: |
|
callback | function |
Your callback that will be invoked. |
|
params | array | <optional> |
The parameters to pass to the callback. Pass an empty array if you don't want to define any, but do wish to set the scope. |
This Tween instance.
Sets this Tween state to COMPLETE_DELAY.
Sets this Tween state to DESTROYED.
Sets this Tween state to FINISHED.
Sets this Tween state to LOOP_DELAY.
Sets this Tween state to PENDING_REMOVE.
Sets this Tween state to PENDING.
Sets this Tween state to REMOVED.
Sets this Tween state to START_DELAY.
Sets the value of the time scale applied to this Tween. 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.
This value is multiplied by the TweenManager.timeScale
.
name | type | description |
---|---|---|
value | number |
The time scale value to set. |
This Tween instance.
Removes all listeners.
Stops the Tween immediately, whatever stage of progress it is at.
If not a part of a Tween Chain it is also flagged for removal by the Tween Manager.
If an onStop
callback has been defined it will automatically invoke it.
The Tween will be removed during the next game frame, but should be considered 'destroyed' from this point on.
Typically, you cannot play a Tween that has been stopped. If you just wish to pause the tween, not destroy it,
then call the pause
method instead and use resume
to continue playback. If you wish to restart the Tween,
use the restart
or seek
methods.
This Tween instance.
Internal method that handles the processing of the complete delay countdown timer and
the dispatch of related events. Called automatically by Tween.update
.
name | type | description |
---|---|---|
delta | number |
The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. |
Internal method that handles the processing of the loop delay countdown timer and
the dispatch of related events. Called automatically by Tween.update
.
name | type | description |
---|---|---|
delta | number |
The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. |
Internal method that handles the processing of the start delay countdown timer and
the dispatch of related events. Called automatically by Tween.update
.
name | type | description |
---|---|---|
delta | number |
The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. |