TweenData

Phaser.Tweens.TweenData

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

optional

description

tween

Phaser.Tweens.Tween

No

The tween this TweenData instance belongs to.

targetIndex

number

No

The target index within the Tween targets array.

key

string

No

The property of the target to tween.

getEnd

Phaser.Types.Tweens.GetEndCallback

No

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

getStart

Phaser.Types.Tweens.GetStartCallback

No

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

getActive

Phaser.Types.Tweens.GetActiveCallback

No

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

ease

function

No

The ease function this tween uses.

delay

function

No

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

duration

number

No

The duration of the tween in milliseconds.

yoyo

boolean

No

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

hold

number

No

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

No

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

No

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

flipX

boolean

No

Should toggleFlipX be called when yoyo or repeat happens?

flipY

boolean

No

Should toggleFlipY be called when yoyo or repeat happens?

interpolation

function

No

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

interpolationData

Array.<number>

No

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


Scope: static

Extends

Phaser.Tweens.BaseTweenData

Source: src/tweens/tween/TweenData.js#L12
Since: 3.60.0

Public Members

current

current: number

Description:

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

Source: src/tweens/tween/TweenData.js#L135
Since: 3.60.0


delay

delay: number

Description:

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

This value is generated by the getDelay function.

Inherits: Phaser.Tweens.BaseTweenData#delay

Source: src/tweens/tween/BaseTweenData.js#L87
Since: 3.60.0


duration

duration: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#duration

Source: src/tweens/tween/BaseTweenData.js#L67
Since: 3.60.0


ease

ease: function

Description:

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

Source: src/tweens/tween/TweenData.js#L108
Since: 3.60.0


elapsed

elapsed: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#elapsed

Source: src/tweens/tween/BaseTweenData.js#L190
Since: 3.60.0


end

end: number

Description:

The targets ending value, as returned by getEndValue.

Source: src/tweens/tween/TweenData.js#L144
Since: 3.60.0


flipX

flipX: boolean

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.

Inherits: Phaser.Tweens.BaseTweenData#flipX

Source: src/tweens/tween/BaseTweenData.js#L159
Since: 3.60.0


flipY

flipY: boolean

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.

Inherits: Phaser.Tweens.BaseTweenData#flipY

Source: src/tweens/tween/BaseTweenData.js#L170
Since: 3.60.0


getActiveValue

getActiveValue: Phaser.Types.Tweens.GetActiveCallback

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.

Source: src/tweens/tween/TweenData.js#L70
Since: 3.60.0


getDelay

getDelay: function

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#getDelay

Source: src/tweens/tween/BaseTweenData.js#L98
Since: 3.60.0


getEndValue

getEndValue: Phaser.Types.Tweens.GetEndCallback

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.

Source: src/tweens/tween/TweenData.js#L82
Since: 3.60.0


getStartValue

getStartValue: Phaser.Types.Tweens.GetStartCallback

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.

Source: src/tweens/tween/TweenData.js#L95
Since: 3.60.0


hold

hold: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#hold

Source: src/tweens/tween/BaseTweenData.js#L117
Since: 3.60.0


interpolation

interpolation: function

Description:

The interpolation function to be used for arrays of data.

Source: src/tweens/tween/TweenData.js#L153
Since: 3.60.0


interpolationData

interpolationData: Array.<number>

Description:

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

Source: src/tweens/tween/TweenData.js#L163
Since: 3.60.0


isCountdown

isCountdown: boolean

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#isCountdown

Source: src/tweens/tween/BaseTweenData.js#L209
Since: 3.60.0


key

key: string

Description:

The property of the target to be tweened.

Source: src/tweens/tween/TweenData.js#L60
Since: 3.60.0


previous

previous: number

Description:

The target value from the previous step.

Source: src/tweens/tween/TweenData.js#L126
Since: 3.60.0


progress

progress: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#progress

Source: src/tweens/tween/BaseTweenData.js#L181
Since: 3.60.0


repeat

repeat: number

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.

Inherits: Phaser.Tweens.BaseTweenData#repeat

Source: src/tweens/tween/BaseTweenData.js#L126
Since: 3.60.0


repeatCounter

repeatCounter: number

Description:

How many repeats are left to run?

Inherits: Phaser.Tweens.BaseTweenData#repeatCounter

Source: src/tweens/tween/BaseTweenData.js#L150
Since: 3.60.0


repeatDelay

repeatDelay: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#repeatDelay

Source: src/tweens/tween/BaseTweenData.js#L141
Since: 3.60.0


start

start: number

Description:

The targets starting value, as returned by getStartValue.

Source: src/tweens/tween/TweenData.js#L117
Since: 3.60.0


state

state: Phaser.Tweens.StateType

Description:

The state of this TweenData.

Inherits: Phaser.Tweens.BaseTweenData#state

Source: src/tweens/tween/BaseTweenData.js#L200
Since: 3.60.0


targetIndex

targetIndex: number

Description:

The index of the target within the Tween targets array.

Inherits: Phaser.Tweens.BaseTweenData#targetIndex

Source: src/tweens/tween/BaseTweenData.js#L58
Since: 3.60.0


totalDuration

totalDuration: number

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#totalDuration

Source: src/tweens/tween/BaseTweenData.js#L77
Since: 3.60.0


tween

tween: Phaser.Tweens.Tween

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#tween

Source: src/tweens/tween/BaseTweenData.js#L49
Since: 3.60.0


yoyo

yoyo: boolean

Description:

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

Inherits: Phaser.Tweens.BaseTweenData#yoyo

Source: src/tweens/tween/BaseTweenData.js#L107
Since: 3.60.0


Public Methods

destroy

<instance> destroy()

Description:

Immediately destroys this TweenData, nulling of all its references.

Overrides: Phaser.Tweens.BaseTweenData#destroy

Source: src/tweens/tween/TweenData.js#L397
Since: 3.60.0


dispatchEvent

<instance> dispatchEvent(event, [callback])

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

optional

description

event

Phaser.Types.Tweens.Event

No

The Event to be dispatched.

callback

Phaser.Types.Tweens.TweenCallbackTypes

Yes

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

Source: src/tweens/tween/TweenData.js#L364
Since: 3.60.0


getTarget

<instance> getTarget()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#getTarget

Source: src/tweens/tween/BaseTweenData.js#L219
Since: 3.60.0


isComplete

<instance> isComplete()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isComplete

Source: src/tweens/tween/BaseTweenData.js#L434
Since: 3.60.0


isCreated

<instance> isCreated()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isCreated

Source: src/tweens/tween/BaseTweenData.js#L343
Since: 3.60.0


isDelayed

<instance> isDelayed()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isDelayed

Source: src/tweens/tween/BaseTweenData.js#L356
Since: 3.60.0


isHolding

<instance> isHolding()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isHolding

Source: src/tweens/tween/BaseTweenData.js#L408
Since: 3.60.0


isPendingRender

<instance> isPendingRender()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isPendingRender

Source: src/tweens/tween/BaseTweenData.js#L369
Since: 3.60.0


isPlayingBackward

<instance> isPlayingBackward()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isPlayingBackward

Source: src/tweens/tween/BaseTweenData.js#L395
Since: 3.60.0


isPlayingForward

<instance> isPlayingForward()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isPlayingForward

Source: src/tweens/tween/BaseTweenData.js#L382
Since: 3.60.0


isRepeating

<instance> isRepeating()

Description:

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

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

Inherits: Phaser.Tweens.BaseTweenData#isRepeating

Source: src/tweens/tween/BaseTweenData.js#L421
Since: 3.60.0


onRepeat

<instance> onRepeat(diff, setStart, isYoyo)

Description:

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

Called automatically by setStateFromStart and setStateFromEnd.

Parameters:

name

type

optional

description

diff

number

No

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

setStart

boolean

No

Set the TweenData start values?

isYoyo

boolean

No

Is this call a Yoyo check?

Fires: Phaser.Tweens.Events#event:TWEEN_REPEAT, Phaser.Tweens.Events#event:TWEEN_YOYO

Inherits: Phaser.Tweens.BaseTweenData#onRepeat

Source: src/tweens/tween/BaseTweenData.js#L569
Since: 3.60.0


reset

<instance> reset([isSeeking])

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

optional

default

description

isSeeking

boolean

Yes

false

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

Overrides: Phaser.Tweens.BaseTweenData#reset

Source: src/tweens/tween/TweenData.js#L173
Since: 3.60.0


setCompleteState

<instance> setCompleteState()

Description:

Sets this TweenData state to COMPLETE.

Inherits: Phaser.Tweens.BaseTweenData#setCompleteState

Source: src/tweens/tween/BaseTweenData.js#L331
Since: 3.60.0


setCreatedState

<instance> setCreatedState()

Description:

Sets this TweenData state to CREATED.

Inherits: Phaser.Tweens.BaseTweenData#setCreatedState

Source: src/tweens/tween/BaseTweenData.js#L247
Since: 3.60.0


setDelayState

<instance> setDelayState()

Description:

Sets this TweenData state to DELAY.

Inherits: Phaser.Tweens.BaseTweenData#setDelayState

Source: src/tweens/tween/BaseTweenData.js#L259
Since: 3.60.0


setHoldState

<instance> setHoldState()

Description:

Sets this TweenData state to HOLD_DELAY.

Inherits: Phaser.Tweens.BaseTweenData#setHoldState

Source: src/tweens/tween/BaseTweenData.js#L307
Since: 3.60.0


setPendingRenderState

<instance> setPendingRenderState()

Description:

Sets this TweenData state to PENDING_RENDER.

Inherits: Phaser.Tweens.BaseTweenData#setPendingRenderState

Source: src/tweens/tween/BaseTweenData.js#L271
Since: 3.60.0


setPlayingBackwardState

<instance> setPlayingBackwardState()

Description:

Sets this TweenData state to PLAYING_BACKWARD.

Inherits: Phaser.Tweens.BaseTweenData#setPlayingBackwardState

Source: src/tweens/tween/BaseTweenData.js#L295
Since: 3.60.0


setPlayingForwardState

<instance> setPlayingForwardState()

Description:

Sets this TweenData state to PLAYING_FORWARD.

Inherits: Phaser.Tweens.BaseTweenData#setPlayingForwardState

Source: src/tweens/tween/BaseTweenData.js#L283
Since: 3.60.0


setRepeatState

<instance> setRepeatState()

Description:

Sets this TweenData state to REPEAT_DELAY.

Inherits: Phaser.Tweens.BaseTweenData#setRepeatState

Source: src/tweens/tween/BaseTweenData.js#L319
Since: 3.60.0


setStateFromEnd

<instance> setStateFromEnd(diff)

Description:

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

Parameters:

name

type

optional

description

diff

number

No

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

Fires: Phaser.Tweens.Events#event:TWEEN_REPEAT, Phaser.Tweens.Events#event:TWEEN_YOYO

Inherits: Phaser.Tweens.BaseTweenData#setStateFromEnd

Source: src/tweens/tween/BaseTweenData.js#L447
Since: 3.60.0


setStateFromStart

<instance> setStateFromStart(diff)

Description:

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

Parameters:

name

type

optional

description

diff

number

No

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

Fires: Phaser.Tweens.Events#event:TWEEN_REPEAT

Inherits: Phaser.Tweens.BaseTweenData#setStateFromStart

Source: src/tweens/tween/BaseTweenData.js#L474
Since: 3.60.0


setTargetValue

<instance> setTargetValue([value])

Description:

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

Parameters:

name

type

optional

description

value

number

Yes

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

Inherits: Phaser.Tweens.BaseTweenData#setTargetValue

Source: src/tweens/tween/BaseTweenData.js#L232
Since: 3.60.0


update

<instance> update(delta)

Description:

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

Parameters:

name

type

optional

description

delta

number

No

The elapsed delta time in ms.

Returns: boolean - true if this TweenData is still playing, or false if it has finished entirely.

Fires: Phaser.Tweens.Events#event:TWEEN_UPDATE, Phaser.Tweens.Events#event:TWEEN_REPEAT

Source: src/tweens/tween/TweenData.js#L206
Since: 3.60.0


Updated on