Class: TweenManager

Phaser.Tweens. TweenManager

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


new TweenManager(scene)

Parameters:
Name Type Description
scene Phaser.Scene

The Scene which owns this Tween Manager.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 17)

Members


scene :Phaser.Scene

The Scene which owns this Tween Manager.

Type:
Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 34)

systems :Phaser.Scenes.Systems

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

Type:
Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 43)

timeScale :number

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
Since: 3.0.0
Default Value:
  • 1
Source: src/tweens/TweenManager.js (Line 52)

Methods


add(config)

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

Parameters:
Name Type Description
config Phaser.Types.Tweens.TweenBuilderConfig | object

The configuration object for the Tween.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 206)
Returns:

The created Tween.

Type
Phaser.Tweens.Tween

addCounter(config)

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.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 246)
Returns:

The created Number Tween.

Type
Phaser.Tweens.Tween

create(config)

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

Parameters:
Name Type Description
config Phaser.Types.Tweens.TweenBuilderConfig | object

The configuration object for the Tween.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 191)
Returns:

The created Tween object.

Type
Phaser.Tweens.Tween

createTimeline( [config])

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

Parameters:
Name Type Argument Description
config Phaser.Types.Tweens.TimelineBuilderConfig <optional>

The configuration object for the Timeline and its Tweens.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 152)
Returns:

The created Timeline object.

Type
Phaser.Tweens.Timeline

destroy()

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

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 762)

each(callback [, scope] [, args])

Passes all Tweens to the given callback.

Parameters:
Name Type Argument Description
callback function

The function to call.

scope object <optional>

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

args * <optional>
<repeatable>

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

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 480)

existing(tween)

Add an existing tween into the active Tween list.

Parameters:
Name Type Description
tween Phaser.Tweens.Tween

The Tween to add.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 227)
Returns:

This Tween Manager object.

Type
Phaser.Tweens.TweenManager

getAllTweens()

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

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 507)
Returns:

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

Type
Array.<Phaser.Tweens.Tween>

getGlobalTimeScale()

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

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 528)
Returns:

The scale of the time delta, usually 1.

Type
number

getTweensOf(target [, includePending])

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 Argument 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?

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 541)
Returns:

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

Type
Array.<Phaser.Tweens.Tween>

isTweening(target)

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

Parameters:
Name Type Description
target object

target Phaser.Tweens.Tween object

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 606)
Returns:

returns if target tween object is active or not

Type
boolean

killAll()

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

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 634)
Returns:

This Tween Manager.

Type
Phaser.Tweens.TweenManager

killTweensOf(target)

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.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 654)
See:
  • #getTweensOf
Returns:

This Tween Manager.

Type
Phaser.Tweens.TweenManager

makeActive(tween)

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.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 447)
Returns:

This Tween Manager object.

Type
Phaser.Tweens.TweenManager

pauseAll()

Pauses all Tweens in this Tween Manager.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 678)
Returns:

This Tween Manager.

Type
Phaser.Tweens.TweenManager

preUpdate()

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
Source: src/tweens/TweenManager.js (Line 313)

remove(tween)

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.

Since: 3.17.0
Source: src/tweens/TweenManager.js (Line 425)
Returns:

This Tween Manager object.

Type
Phaser.Tweens.TweenManager

resumeAll()

Resumes all Tweens in this Tween Manager.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 698)
Returns:

This Tween Manager.

Type
Phaser.Tweens.TweenManager

setGlobalTimeScale(value)

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.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 718)
Returns:

This Tween Manager.

Type
Phaser.Tweens.TweenManager

shutdown()

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
Source: src/tweens/TweenManager.js (Line 737)

stagger(value, config)

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.

Since: 3.19.0
Source: src/tweens/TweenManager.js (Line 267)
Returns:

The stagger function.

Type
function

timeline( [config])

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

Parameters:
Name Type Argument Description
config Phaser.Types.Tweens.TimelineBuilderConfig <optional>

The configuration object for the Timeline and its Tweens.

Since: 3.0.0
Source: src/tweens/TweenManager.js (Line 167)
Returns:

The created Timeline object.

Type
Phaser.Tweens.Timeline

update(timestamp, delta)

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
Source: src/tweens/TweenManager.js (Line 393)