Phaser API Documentation

  Version: 
Filter

The TweenData is a class that contains a single target and property that is being tweened.

Tweens create TweenData instances when they are created, with one TweenData instance per target, per property. A Tween can own multiple TweenData instances, but a TweenData only ever belongs to a single Tween.

You should not typically create these yourself, but rather use the TweenBuilder, or the Tween.add method.

Prior to Phaser 3.60 the TweenData was just an object, but was refactored to a class, to make it responsible for its own state and updating.

Constructor:

new TweenData(tween, targetIndex, key, getEnd, getStart, getActive, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY, interpolation, interpolationData)

Parameters:

name type description
tween Phaser.Tweens.Tween

The tween this TweenData instance belongs to.

targetIndex number

The target index within the Tween targets array.

key string

The property of the target to tween.

getEnd Phaser.Types.Tweens.GetEndCallback

What the property will be at the END of the Tween.

getStart Phaser.Types.Tweens.GetStartCallback

What the property will be at the START of the Tween.

getActive Phaser.Types.Tweens.GetActiveCallback

If not null, is invoked immediately as soon as the TweenData is running, and is set on the target property.

ease function

The ease function this tween uses.

delay function

Function that returns the time in milliseconds before tween will start.

duration number

The duration of the tween in milliseconds.

yoyo boolean

Determines whether the tween should return back to its start value after hold has expired.

hold number

Function that returns the time in milliseconds the tween will pause before repeating or returning to its starting value if yoyo is set to true.

repeat number

Function that returns the number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice.

repeatDelay number

Function that returns the time in milliseconds before the repeat will start.

flipX boolean

Should toggleFlipX be called when yoyo or repeat happens?

flipY boolean

Should toggleFlipY be called when yoyo or repeat happens?

interpolation function

The interpolation function to be used for arrays of data. Defaults to 'null'.

interpolationData Array.<number>

The array of interpolation data to be set. Defaults to 'null'.

Since: 3.60.0

Extends


Members

current: number
Focus
Focus

Description:

The targets current value, as recorded in the most recent step.

Type:
number
Since: 3.60.0
Focus
Focus
delay: number
Focus
Focus

Description:

The time, in milliseconds, before this tween will start playing.

This value is generated by the getDelay function.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#delay
Since: 3.60.0
Focus
Focus
duration: number
Focus
Focus

Description:

The duration of the tween in milliseconds, excluding any time required for yoyo or repeats.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#duration
Since: 3.60.0
Focus
Focus
ease: function
Focus
Focus

Description:

The ease function this Tween uses to calculate the target value.

Type:
function
Since: 3.60.0
Focus
Focus
elapsed: number
Focus
Focus

Description:

The amount of time, in milliseconds, that has elapsed since this TweenData was made active.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#elapsed
Since: 3.60.0
Focus
Focus
end: number
Focus
Focus

Description:

The targets ending value, as returned by getEndValue.

Type:
number
Since: 3.60.0
Focus
Focus
flipX: boolean
Focus
Focus

Description:

If true this Tween will call toggleFlipX on the Tween target whenever it yoyo's or repeats. It will only be called if the target has a function matching this name, like most Phaser GameObjects do.

Type:
boolean
Inherited from: Phaser.Tweens.BaseTweenData#flipX
Since: 3.60.0
Focus
Focus
flipY: boolean
Focus
Focus

Description:

If true this Tween will call toggleFlipY on the Tween target whenever it yoyo's or repeats. It will only be called if the target has a function matching this name, like most Phaser GameObjects do.

Type:
boolean
Inherited from: Phaser.Tweens.BaseTweenData#flipY
Since: 3.60.0
Focus
Focus
<nullable> getActiveValue: Phaser.Types.Tweens.GetActiveCallback
Focus
Focus

Description:

A function that returns what to set the target property to, the moment the TweenData is invoked.

This is called when this TweenData is initialised or reset.

Type:
Since: 3.60.0
Focus
Focus
getDelay: function
Focus
Focus

Description:

This function returns the value to be used for TweenData.delay.

Type:
function
Inherited from: Phaser.Tweens.BaseTweenData#getDelay
Since: 3.60.0
Focus
Focus

Description:

A function that returns what to set the target property to at the end of the tween.

This is called when the tween starts playing, after any initial start delay, or if the tween is reset, or is set to repeat.

Type:
Since: 3.60.0
Focus
Focus

Description:

A function that returns what to set the target property to at the start of the tween.

This is called when the tween starts playing, after any initial start delay, or if the tween is reset, or is set to repeat.

Type:
Since: 3.60.0
Focus
Focus
hold: number
Focus
Focus

Description:

The time, in milliseconds, before this tween will start a yoyo to repeat.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#hold
Since: 3.60.0
Focus
Focus
<nullable> interpolation: function
Focus
Focus

Description:

The interpolation function to be used for arrays of data.

Type:
function
Default: null
Since: 3.60.0
Focus
Focus
<nullable> interpolationData: Array.<number>
Focus
Focus

Description:

The array of data to interpolate, if interpolation is being used.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
isCountdown: boolean
Focus
Focus

Description:

Is this Tween Data currently waiting for a countdown to elapse, or not?

Type:
boolean
Inherited from: Phaser.Tweens.BaseTweenData#isCountdown
Since: 3.60.0
Focus
Focus
<readonly> key: string
Focus
Focus

Description:

The property of the target to be tweened.

Type:
string
Since: 3.60.0
Focus
Focus
progress: number
Focus
Focus

Description:

A value between 0 and 1 holding the progress of this TweenData.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#progress
Since: 3.60.0
Focus
Focus
repeat: number
Focus
Focus

Description:

The number of times this tween will repeat.

The tween will always run once regardless of this value, so a repeat value of '1' will play the tween twice: I.e. the original play-through and then it repeats that once (1).

If this value is set to -1 this tween will repeat forever.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#repeat
Since: 3.60.0
Focus
Focus
repeatCounter: number
Focus
Focus

Description:

How many repeats are left to run?

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#repeatCounter
Since: 3.60.0
Focus
Focus
repeatDelay: number
Focus
Focus

Description:

The time, in milliseconds, before the repeat will start.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#repeatDelay
Since: 3.60.0
Focus
Focus
start: number
Focus
Focus

Description:

The targets starting value, as returned by getStartValue.

Type:
number
Since: 3.60.0
Focus
Focus

Description:

The state of this TweenData.

Type:
Inherited from: Phaser.Tweens.BaseTweenData#state
Since: 3.60.0
Focus
Focus
targetIndex: number
Focus
Focus

Description:

The index of the target within the Tween targets array.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#targetIndex
Since: 3.60.0
Focus
Focus
totalDuration: number
Focus
Focus

Description:

The total calculated duration, in milliseconds, of this TweenData. Factoring in the duration, repeats, delays and yoyos.

Type:
number
Inherited from: Phaser.Tweens.BaseTweenData#totalDuration
Since: 3.60.0
Focus
Focus

Description:

A reference to the Tween that this TweenData instance belongs to.

Type:
Inherited from: Phaser.Tweens.BaseTweenData#tween
Since: 3.60.0
Focus
Focus
yoyo: boolean
Focus
Focus

Description:

Will the Tween ease back to its starting values, after reaching the end and any hold value that may be set?

Type:
boolean
Inherited from: Phaser.Tweens.BaseTweenData#yoyo
Since: 3.60.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Immediately destroys this TweenData, nulling of all its references.

Overrides: Phaser.Tweens.BaseTweenData#destroy
Since: 3.60.0
Focus
Focus
dispatchEvent(event, [callback])
Focus
Focus

Description:

Internal method that will emit a TweenData based Event on the parent Tween and also invoke the given callback, if provided.

Parameters:

name type arguments description
event Phaser.Types.Tweens.Event

The Event to be dispatched.

callback Phaser.Types.Tweens.TweenCallbackTypes <optional>

The name of the callback to be invoked. Can be null or undefined to skip invocation.

Since: 3.60.0
Focus
Focus
getTarget()
Focus
Focus

Description:

Returns a reference to the target object belonging to this TweenData.

Returns:
Description:

The target object. Can be any JavaScript object, but is typically a Game Object.

Type:
  • object
Inherited from: Phaser.Tweens.BaseTweenData#getTarget
Since: 3.60.0
Focus
Focus
isComplete()
Focus
Focus

Description:

Returns true if this TweenData has a current state of COMPLETE, otherwise false.

Returns:
Description:

true if this TweenData has a current state of COMPLETE, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isComplete
Since: 3.60.0
Focus
Focus
isCreated()
Focus
Focus

Description:

Returns true if this TweenData has a current state of CREATED, otherwise false.

Returns:
Description:

true if this TweenData has a current state of CREATED, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isCreated
Since: 3.60.0
Focus
Focus
isDelayed()
Focus
Focus

Description:

Returns true if this TweenData has a current state of DELAY, otherwise false.

Returns:
Description:

true if this TweenData has a current state of DELAY, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isDelayed
Since: 3.60.0
Focus
Focus
isHolding()
Focus
Focus

Description:

Returns true if this TweenData has a current state of HOLD_DELAY, otherwise false.

Returns:
Description:

true if this TweenData has a current state of HOLD_DELAY, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isHolding
Since: 3.60.0
Focus
Focus
isPendingRender()
Focus
Focus

Description:

Returns true if this TweenData has a current state of PENDING_RENDER, otherwise false.

Returns:
Description:

true if this TweenData has a current state of PENDING_RENDER, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isPendingRender
Since: 3.60.0
Focus
Focus
isPlayingBackward()
Focus
Focus

Description:

Returns true if this TweenData has a current state of PLAYING_BACKWARD, otherwise false.

Returns:
Description:

true if this TweenData has a current state of PLAYING_BACKWARD, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isPlayingBackward
Since: 3.60.0
Focus
Focus
isPlayingForward()
Focus
Focus

Description:

Returns true if this TweenData has a current state of PLAYING_FORWARD, otherwise false.

Returns:
Description:

true if this TweenData has a current state of PLAYING_FORWARD, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isPlayingForward
Since: 3.60.0
Focus
Focus
isRepeating()
Focus
Focus

Description:

Returns true if this TweenData has a current state of REPEAT_DELAY, otherwise false.

Returns:
Description:

true if this TweenData has a current state of REPEAT_DELAY, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Tweens.BaseTweenData#isRepeating
Since: 3.60.0
Focus
Focus
onRepeat(diff, setStart, isYoyo)
Focus
Focus

Description:

Internal method that handles repeating or yoyo'ing this TweenData.

Called automatically by setStateFromStart and setStateFromEnd.

Parameters:

name type description
diff number

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

setStart boolean

Set the TweenData start values?

isYoyo boolean

Is this call a Yoyo check?

Inherited from: Phaser.Tweens.BaseTweenData#onRepeat
Since: 3.60.0
Focus
Focus
reset([isSeeking])
Focus
Focus

Description:

Internal method that resets this Tween Data entirely, including the progress and elapsed values.

Called automatically by the parent Tween. Should not be called directly.

Parameters:

name type arguments Default description
isSeeking boolean <optional> false

Is the Tween Data being reset as part of a Tween seek?

Overrides: Phaser.Tweens.BaseTweenData#reset
Since: 3.60.0
Focus
Focus
setCompleteState()
Focus
Focus

Description:

Sets this TweenData state to COMPLETE.

Inherited from: Phaser.Tweens.BaseTweenData#setCompleteState
Since: 3.60.0
Focus
Focus
setCreatedState()
Focus
Focus

Description:

Sets this TweenData state to CREATED.

Inherited from: Phaser.Tweens.BaseTweenData#setCreatedState
Since: 3.60.0
Focus
Focus
setDelayState()
Focus
Focus

Description:

Sets this TweenData state to DELAY.

Inherited from: Phaser.Tweens.BaseTweenData#setDelayState
Since: 3.60.0
Focus
Focus
setHoldState()
Focus
Focus

Description:

Sets this TweenData state to HOLD_DELAY.

Inherited from: Phaser.Tweens.BaseTweenData#setHoldState
Since: 3.60.0
Focus
Focus
setPendingRenderState()
Focus
Focus

Description:

Sets this TweenData state to PENDING_RENDER.

Inherited from: Phaser.Tweens.BaseTweenData#setPendingRenderState
Since: 3.60.0
Focus
Focus
setPlayingBackwardState()
Focus
Focus

Description:

Sets this TweenData state to PLAYING_BACKWARD.

Inherited from: Phaser.Tweens.BaseTweenData#setPlayingBackwardState
Since: 3.60.0
Focus
Focus
setPlayingForwardState()
Focus
Focus

Description:

Sets this TweenData state to PLAYING_FORWARD.

Inherited from: Phaser.Tweens.BaseTweenData#setPlayingForwardState
Since: 3.60.0
Focus
Focus
setRepeatState()
Focus
Focus

Description:

Sets this TweenData state to REPEAT_DELAY.

Inherited from: Phaser.Tweens.BaseTweenData#setRepeatState
Since: 3.60.0
Focus
Focus
setStateFromEnd(diff)
Focus
Focus

Description:

Internal method used as part of the playback process that checks if this TweenData should yoyo, repeat, or has completed.

Parameters:

name type description
diff number

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

Inherited from: Phaser.Tweens.BaseTweenData#setStateFromEnd
Since: 3.60.0
Focus
Focus
setStateFromStart(diff)
Focus
Focus

Description:

Internal method used as part of the playback process that checks if this TweenData should repeat or has completed.

Parameters:

name type description
diff number

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

Inherited from: Phaser.Tweens.BaseTweenData#setStateFromStart
Since: 3.60.0
Focus
Focus
setTargetValue([value])
Focus
Focus

Description:

Sets this TweenData's target object property to be the given value.

Parameters:

name type arguments description
value number <optional>

The value to set on the target. If not given, sets it to the last current value.

Inherited from: Phaser.Tweens.BaseTweenData#setTargetValue
Since: 3.60.0
Focus
Focus
update(delta)
Focus
Focus

Description:

Internal method that advances this TweenData based on the delta value given.

Parameters:

name type description
delta number

The elapsed delta time in ms.

Returns:
Description:

true if this TweenData is still playing, or false if it has finished entirely.

Type:
  • boolean
Since: 3.60.0
Focus
Focus