Class: Tween

Phaser.Tweens. Tween

A Tween is able to manipulate the properties of one or more objects to any given value, based on a duration and type of ease. They are rarely instantiated directly and instead should be created via the TweenManager.


new Tween(parent, data, targets)

Parameters:
Name Type Description
parent Phaser.Tweens.TweenManager | Phaser.Tweens.Timeline

A reference to the parent of this Tween. Either the Tween Manager or a Tween Timeline instance.

data Array.<Phaser.Types.Tweens.TweenDataConfig>

An array of TweenData objects, each containing a unique property to be tweened.

targets array

An array of targets to be tweened.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 12)

Members


calculatedOffset :number

Set only if this Tween is part of a Timeline. The calculated offset amount.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 170)

callbacks :object

An object containing the various Tween callback references.

Type:
  • object
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 269)

completeDelay :number

Time in ms/frames before the 'onComplete' event fires. This never fires if loop = -1 (as it never completes)

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 140)

countdown :number

Countdown timer (used by timeline offset, loopDelay and completeDelay)

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 150)

data :Array.<Phaser.Types.Tweens.TweenDataConfig>

An array of TweenData objects, each containing a unique property and target being tweened.

Type:
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 52)

duration :number

Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 229)

elapsed :number

Elapsed time in ms/frames of this run through the Tween.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 209)

loop :number

Loop this tween? Can be -1 for an infinite loop, or an integer. When enabled it will play through ALL TweenDatas again. Use TweenData.repeat to loop a single element.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 109)

loopCounter :number

How many loops are left to run?

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 130)

loopDelay :number

Time in ms/frames before the tween loops.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 120)

offset :number

Set only if this Tween is part of a Timeline.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 160)

parent :Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline

A reference to the parent of this Tween. Either the Tween Manager or a Tween Timeline instance.

Type:
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 33)

parentIsTimeline :boolean

Is the parent of this Tween a Timeline?

Type:
  • boolean
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 43)

paused :boolean

Does the Tween start off paused? (if so it needs to be started with Tween.play)

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/tweens/tween/Tween.js (Line 199)

progress :number

Value between 0 and 1. The amount through the Tween, excluding loops.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 239)

state :integer

The current state of the tween

Type:
  • integer
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 180)

targets :Array.<object>

An array of references to the target/s this Tween is operating on.

Type:
  • Array.<object>
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 70)

timeScale :number

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. Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/tweens/tween/Tween.js (Line 98)

totalData :integer

The cached length of the data array.

Type:
  • integer
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 61)

totalDuration :number

Time in ms/frames for the Tween to complete (including looping)

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 249)

totalElapsed :number

Total elapsed time in ms/frames of the entire Tween, including looping.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 219)

totalProgress :number

Value between 0 and 1. The amount through the entire Tween, including looping.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/tweens/tween/Tween.js (Line 259)

totalTargets :integer

Cached target total (not necessarily the same as the data total)

Type:
  • integer
Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 79)

useFrames :boolean

If true then duration, delay, etc values are all frame totals.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/tweens/tween/Tween.js (Line 88)

Methods


calcDuration()

Internal method that calculates the overall duration of the Tween.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 441)

complete( [delay])

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 have an onComplete callback, then call Tween.stop instead.

Parameters:
Name Type Argument Default Description
delay number <optional>
0

The time to wait before invoking the complete callback. If zero it will fire immediately.

Since: 3.2.0
Source: src/tweens/tween/Tween.js (Line 878)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

getTimeScale()

Returns the scale of the time applied to this Tween.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 319)
Returns:

The timescale of this tween (between 0 and 1)

Type
number

getValue()

Returns the current value of the Tween.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 289)
Returns:

The value of the Tween.

Type
number

hasTarget(target)

See if this Tween is currently acting upon the given target.

Parameters:
Name Type Description
target object

The target to check against this Tween.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 358)
Returns:

true if the given target is a target of this Tween, otherwise false.

Type
boolean

init()

Called by TweenManager.preUpdate as part of its loop to check pending and active tweens. Should not be called directly.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 505)
Returns:

Returns true if this Tween should be moved from the pending list to the active list by the Tween Manager.

Type
boolean

isPaused()

Checks if the Tween is currently paused.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 345)
Returns:

true if the Tween is paused, otherwise false.

Type
boolean

isPlaying()

Checks if the Tween is currently active.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 332)
Returns:

true if the Tween is active, otherwise false.

Type
boolean

nextState()

Internal method that advances to the next state of the Tween during playback.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 555)

pause()

Pauses the Tween immediately. Use resume to continue playback.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 610)
Returns:
  • This Tween instance.
Type
Phaser.Tweens.Tween

play( [resetFromTimeline])

Starts a Tween playing.

You only need to call this method if you have configured the tween to be paused on creation.

If the Tween is already playing, calling this method again will have no effect. If you wish to restart the Tween, use Tween.restart instead.

Calling this method after the Tween has completed will start the Tween playing again from the start. This is the same as calling Tween.seek(0) and then Tween.play().

Parameters:
Name Type Argument Default Description
resetFromTimeline boolean <optional>
false

Is this Tween being played as part of a Timeline?

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

This Tween instance.

Type
Phaser.Tweens.Tween

remove()

Immediately removes this Tween from the TweenManager and all of its internal arrays, no matter what stage it as it. 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.

Since: 3.17.0
Source: src/tweens/tween/Tween.js (Line 919)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

resetTweenData(resetFromLoop)

Internal method that resets all of the Tween Data, including the progress and elapsed values.

Parameters:
Name Type Description
resetFromLoop boolean

Has this method been called as part of a loop?

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 717)

restart()

Restarts the tween from the beginning.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 412)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

resume()

Resumes the playback of a previously paused Tween.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 761)
Returns:
  • This Tween instance.
Type
Phaser.Tweens.Tween

seek(toPosition)

Attempts to seek to a specific position in a Tween.

Parameters:
Name Type Description
toPosition number

A value between 0 and 1 which represents the progress point to seek to.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 785)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

setCallback(type, callback [, params] [, scope])

Sets an event based callback to be invoked during playback.

Parameters:
Name Type Argument Description
type string

Type of the callback.

callback function

Callback function.

params array <optional>

An array of parameters for specified callbacks types.

scope object <optional>

The context the callback will be invoked in.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 858)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

setStateFromEnd(tween, tweenData, diff)

Internal method used as part of the playback process that sets a tween to play in reverse.

Parameters:
Name Type Description
tween Phaser.Tweens.Tween

The Tween to update.

tweenData Phaser.Types.Tweens.TweenDataConfig

The TweenData property to update.

diff number

Any extra time that needs to be accounted for in the elapsed and progress values.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 1086)
Returns:

The state of this Tween.

Type
integer

setStateFromStart(tween, tweenData, diff)

Internal method used as part of the playback process that sets a tween to play from the start.

Parameters:
Name Type Description
tween Phaser.Tweens.Tween

The Tween to update.

tweenData Phaser.Types.Tweens.TweenDataConfig

The TweenData property to update.

diff number

Any extra time that needs to be accounted for in the elapsed and progress values.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 1190)
Returns:

The state of this Tween.

Type
integer

setTimeScale(value)

Set the scale 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.

Parameters:
Name Type Description
value number

The scale factor for timescale.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 302)
Returns:
  • This Tween instance.
Type
Phaser.Tweens.Tween

stop( [resetTo])

Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager.

Parameters:
Name Type Argument Description
resetTo number <optional>

If you want to seek the tween, provide a value between 0 and 1.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 938)
Returns:

This Tween instance.

Type
Phaser.Tweens.Tween

update(timestamp, delta)

Internal method that advances the Tween based on the time values.

Parameters:
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.

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 980)
Returns:

Returns true if this Tween has finished and should be removed from the Tween Manager, otherwise returns false.

Type
boolean

updateTo(key, value [, startToCurrent])

Updates the value of a property of this Tween to a new value, without adjusting the Tween duration or current progress.

You can optionally tell it to set the 'start' value to be the current value (before the change).

Parameters:
Name Type Argument Default Description
key string

The property to set the new value for.

value *

The new value of the property.

startToCurrent boolean <optional>
false

Should this change set the start value to be the current value?

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 373)
Returns:
  • This Tween instance.
Type
Phaser.Tweens.Tween

updateTweenData(tween, tweenData, delta)

Internal method that advances the TweenData based on the time value given.

Parameters:
Name Type Description
tween Phaser.Tweens.Tween

The Tween to update.

tweenData Phaser.Types.Tweens.TweenDataConfig

The TweenData property to update.

delta number

Either a value in ms, or 1 if Tween.useFrames is true

Since: 3.0.0
Source: src/tweens/tween/Tween.js (Line 1254)
Returns:

[description]

Type
boolean