Phaser API Documentation

  Version: 
Filter

The Tween Manager is a default Scene Plugin which controls and updates Tweens and Timelines.

Constructor:

new TweenManager(scene)

Parameters:

name type description
scene Phaser.Scene

The Scene which owns this Tween Manager.

Since: 3.0.0

Members

<private> _active: array
Focus
Focus

Description:

An array of Tweens and Timelines which are still incomplete and are actively processed by the Tween Manager.

Type:
array
Since: 3.0.0
Focus
Focus
<private> _add: array
Focus
Focus

Description:

An array of Tweens and Timelines which will be added to the Tween Manager at the start of the frame.

Type:
array
Since: 3.0.0
Focus
Focus
<private> _destroy: array
Focus
Focus

Description:

An array of Tweens and Timelines which will be removed from the Tween Manager at the start of the frame.

Type:
array
Since: 3.0.0
Focus
Focus
<private> _pending: array
Focus
Focus

Description:

An array of Tweens and Timelines pending to be later added to the Tween Manager.

Type:
array
Since: 3.0.0
Focus
Focus
<private> _toProcess: number
Focus
Focus

Description:

The number of Tweens and Timelines which need to be processed by the Tween Manager at the start of the frame.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
scene: Phaser.Scene
Focus
Focus

Description:

The Scene which owns this Tween Manager.

Type:
Since: 3.0.0
Focus
Focus

Description:

The Systems object of the Scene which owns this Tween Manager.

Type:
Since: 3.0.0
Focus
Focus
timeScale: number
Focus
Focus

Description:

The time scale of the Tween Manager.

This value scales the time delta between two frames, thus influencing the speed of time for all Tweens owned by this Tween Manager.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus

Methods

add(config)
Focus
Focus

Description:

Create a Tween and add it to the active Tween list.

Parameters:

name type description
config object | Phaser.Types.Tweens.TweenBuilderConfig

The configuration object for the Tween.

Returns:
Description:

The created Tween.

Since: 3.0.0
Focus
Focus
addCounter(config)
Focus
Focus

Description:

Create a Number Tween and add it to the active Tween list.

Parameters:

name type description
config Phaser.Types.Tweens.NumberTweenBuilderConfig

The configuration object for the Number Tween.

Returns:
Description:

The created Number Tween.

Since: 3.0.0
Focus
Focus
<private> boot()
Focus
Focus

Description:

This method is called automatically, only once, when the Scene is first created. Do not invoke it directly.

Since: 3.5.1
Focus
Focus
create(config)
Focus
Focus

Description:

Create a Tween and return it, but do NOT add it to the active or pending Tween lists.

Parameters:

name type description
config object | Phaser.Types.Tweens.TweenBuilderConfig

The configuration object for the Tween.

Returns:
Description:

The created Tween object.

Since: 3.0.0
Focus
Focus
createTimeline([config])
Focus
Focus

Description:

Create a Tween Timeline and return it, but do NOT add it to the active or pending Tween lists.

Parameters:

name type arguments description
config Phaser.Types.Tweens.TimelineBuilderConfig <optional>

The configuration object for the Timeline and its Tweens.

Returns:
Description:

The created Timeline object.

Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

The Scene that owns this plugin is being destroyed. We need to shutdown and then kill off all external references.

Since: 3.0.0
Focus
Focus
each(callback, [scope], [args])
Focus
Focus

Description:

Passes all Tweens to the given callback.

Parameters:

name type arguments description
callback function

The function to call.

scope object <optional>

The scope (this object) to call the function with.

args * <optional>

The arguments to pass into the function. Its first argument will always be the Tween currently being iterated.

Since: 3.0.0
Focus
Focus
existing(tween)
Focus
Focus

Description:

Add an existing tween into the active Tween list.

Parameters:

name type description
tween Phaser.Tweens.Tween

The Tween to add.

Returns:
Description:

This Tween Manager object.

Since: 3.0.0
Focus
Focus
getAllTweens()
Focus
Focus

Description:

Returns an array of all active Tweens and Timelines in the Tween Manager.

Returns:
Description:

A new array containing references to all active Tweens and Timelines.

Type:
Since: 3.0.0
Focus
Focus
getGlobalTimeScale()
Focus
Focus

Description:

Returns the scale of the time delta for all Tweens and Timelines owned by this Tween Manager.

Returns:
Description:

The scale of the time delta, usually 1.

Type:
  • number
Since: 3.0.0
Focus
Focus
getTweensOf(target, [includePending])
Focus
Focus

Description:

Returns an array of all Tweens or Timelines in the Tween Manager which affect the given target or array of targets.

Only the currently active tweens are tested. A tween that has completed and is awaiting removal will not be included in the results.

If you wish to also search pending tweens, use the includePending flag.

Parameters:

name type arguments Default description
target object | array

The target to look for. Provide an array to look for multiple targets.

includePending boolean <optional> false

Also check for pending tweens, not just active ones?

Returns:
Description:

A new array containing all Tweens and Timelines which affect the given target(s).

Type:
Since: 3.0.0
Focus
Focus
isTweening(target)
Focus
Focus

Description:

Checks if the given object is being affected by a playing Tween.

Parameters:

name type description
target object

target Phaser.Tweens.Tween object

Returns:
Description:

returns if target tween object is active or not

Type:
  • boolean
Since: 3.0.0
Focus
Focus
killAll()
Focus
Focus

Description:

Stops all Tweens in this Tween Manager. They will be removed at the start of the frame.

Returns:
Description:

This Tween Manager.

Since: 3.0.0
Focus
Focus
killTweensOf(target)
Focus
Focus

Description:

Stops all Tweens which affect the given target or array of targets. The Tweens will be removed from the Tween Manager at the start of the frame.

Parameters:

name type description
target object | array

The target to look for. Provide an array to look for multiple targets.

Returns:
Description:

This Tween Manager.

Since: 3.0.0
Focus
Focus
makeActive(tween)
Focus
Focus

Description:

Checks if a Tween or Timeline is active and adds it to the Tween Manager at the start of the frame if it isn't.

Parameters:

name type description
tween Phaser.Tweens.Tween

The Tween to check.

Returns:
Description:

This Tween Manager object.

Since: 3.0.0
Focus
Focus
pauseAll()
Focus
Focus

Description:

Pauses all Tweens in this Tween Manager.

Returns:
Description:

This Tween Manager.

Since: 3.0.0
Focus
Focus
preUpdate()
Focus
Focus

Description:

Updates the Tween Manager's internal lists at the start of the frame.

This method will return immediately if no changes have been indicated.

Since: 3.0.0
Focus
Focus
remove(tween)
Focus
Focus

Description:

Removes the given tween from the Tween Manager, regardless of its state (pending or active).

Parameters:

name type description
tween Phaser.Tweens.Tween

The Tween to be removed.

Returns:
Description:

This Tween Manager object.

Since: 3.17.0
Focus
Focus
resumeAll()
Focus
Focus

Description:

Resumes all Tweens in this Tween Manager.

Returns:
Description:

This Tween Manager.

Since: 3.0.0
Focus
Focus
setGlobalTimeScale(value)
Focus
Focus

Description:

Sets a new scale of the time delta for this Tween Manager.

The time delta is the time elapsed between two consecutive frames and influences the speed of time for this Tween Manager and all Tweens it owns. 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 all Tweens.

Parameters:

name type description
value number

The new scale of the time delta, where 1 is the normal speed.

Returns:
Description:

This Tween Manager.

Since: 3.0.0
Focus
Focus
shutdown()
Focus
Focus

Description:

The Scene that owns this plugin is shutting down. We need to kill and reset all internal properties as well as stop listening to Scene events.

Since: 3.0.0
Focus
Focus
stagger(value, config)
Focus
Focus

Description:

Creates a Stagger function to be used by a Tween property.

The stagger function will allow you to stagger changes to the value of the property across all targets of the tween.

This is only worth using if the tween has multiple targets.

The following will stagger the delay by 100ms across all targets of the tween, causing them to scale down to 0.2 over the duration specified:

this.tweens.add({
    targets: [ ... ],
    scale: 0.2,
    ease: 'linear',
    duration: 1000,
    delay: this.tweens.stagger(100)
});

The following will stagger the delay by 500ms across all targets of the tween using a 10 x 6 grid, staggering from the center out, using a cubic ease.

this.tweens.add({
    targets: [ ... ],
    scale: 0.2,
    ease: 'linear',
    duration: 1000,
    delay: this.tweens.stagger(500, { grid: [ 10, 6 ], from: 'center', ease: 'cubic.out' })
});

Parameters:

name type description
value number | Array.<number>

The amount to stagger by, or an array containing two elements representing the min and max values to stagger between.

config Phaser.Types.Tweens.StaggerConfig

The configuration object for the Stagger function.

Returns:
Description:

The stagger function.

Type:
  • function
Since: 3.19.0
Focus
Focus
<private> start()
Focus
Focus

Description:

This method is called automatically by the Scene when it is starting up. It is responsible for creating local systems, properties and listening for Scene events. Do not invoke it directly.

Since: 3.5.0
Focus
Focus
timeline([config])
Focus
Focus

Description:

Create a Tween Timeline and add it to the active Tween list.

Parameters:

name type arguments description
config Phaser.Types.Tweens.TimelineBuilderConfig <optional>

The configuration object for the Timeline and its Tweens.

Returns:
Description:

The created Timeline object.

Since: 3.0.0
Focus
Focus
update(timestamp, delta)
Focus
Focus

Description:

Updates all Tweens and Timelines of the Tween Manager.

Parameters:

name type description
timestamp number

The current time in milliseconds.

delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Focus
Focus