Skip to main content
Version: Phaser v4.1.0

BaseTweenData

BaseTweenData is the class that the TweenData and TweenFrameData classes extend from. You should not typically instantiate this class directly, but instead use it to form your own tween data classes from, should you require it.

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 BaseTweenData(tween, targetIndex, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY)

Parameters

nametypeoptionaldescription
tweenPhaser.Tweens.TweenNoThe tween this TweenData instance belongs to.
targetIndexnumberNoThe target index within the Tween targets array.
delayfunctionNoFunction that returns the time in milliseconds before tween will start.
durationnumberNoThe duration of the tween in milliseconds.
yoyobooleanNoDetermines whether the tween should return back to its start value after hold has expired.
holdnumberNoThe time in milliseconds the tween will pause before repeating or returning to its starting value if yoyo is set to true.
repeatnumberNoThe 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.
repeatDelaynumberNoThe time in milliseconds before the repeat will start.
flipXbooleanNoShould toggleFlipX be called when yoyo or repeat happens?
flipYbooleanNoShould toggleFlipY be called when yoyo or repeat happens?

Scope: static

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

Public Members​

delay​

delay: number​

Description:

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

This value is generated by the getDelay function.

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


duration​

duration: number​

Description:

The duration of the tween in milliseconds, excluding any time required for yoyo or repeats. A tween can never have a duration of zero, so this will be set to 0.01 if the value is incorrectly less than or equal to zero.

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


elapsed​

elapsed: number​

Description:

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

Source: src/tweens/tween/BaseTweenData.js#L184
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.

Source: src/tweens/tween/BaseTweenData.js#L153
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.

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


getDelay​

getDelay: function​

Description:

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

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


hold​

hold: number​

Description:

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

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


isCountdown​

isCountdown: boolean​

Description:

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

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


progress​

progress: number​

Description:

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

Source: src/tweens/tween/BaseTweenData.js#L175
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.

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


repeatCounter​

repeatCounter: number​

Description:

How many repeats are left to run?

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


repeatDelay​

repeatDelay: number​

Description:

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

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


state​

state: Phaser.Tweens.StateType​

Description:

The state of this TweenData.

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


targetIndex​

targetIndex: number​

Description:

The index of the target within the Tween targets array.

Source: src/tweens/tween/BaseTweenData.js#L51
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.

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


tween​

tween: Phaser.Tweens.Tween​

Description:

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

Source: src/tweens/tween/BaseTweenData.js#L42
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?

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


Public Methods​

destroy​

<instance> destroy()​

Description:

Immediately destroys this TweenData, nulling of all its references.

Source: src/tweens/tween/BaseTweenData.js#L646
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.

Source: src/tweens/tween/BaseTweenData.js#L213
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.

Source: src/tweens/tween/BaseTweenData.js#L428
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.

Source: src/tweens/tween/BaseTweenData.js#L337
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.

Source: src/tweens/tween/BaseTweenData.js#L350
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.

Source: src/tweens/tween/BaseTweenData.js#L402
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.

Source: src/tweens/tween/BaseTweenData.js#L363
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.

Source: src/tweens/tween/BaseTweenData.js#L389
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.

Source: src/tweens/tween/BaseTweenData.js#L376
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.

Source: src/tweens/tween/BaseTweenData.js#L415
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:

nametypeoptionaldescription
diffnumberNoAny extra time that needs to be accounted for in the elapsed and progress values.
setStartbooleanNoSet the TweenData start values?
isYoyobooleanNoIs this call a Yoyo check?

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

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


reset​

<instance> reset()​

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.

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


setCompleteState​

<instance> setCompleteState()​

Description:

Sets this TweenData state to COMPLETE.

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


setCreatedState​

<instance> setCreatedState()​

Description:

Sets this TweenData state to CREATED.

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


setDelayState​

<instance> setDelayState()​

Description:

Sets this TweenData state to DELAY.

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


setHoldState​

<instance> setHoldState()​

Description:

Sets this TweenData state to HOLD_DELAY.

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


setPendingRenderState​

<instance> setPendingRenderState()​

Description:

Sets this TweenData state to PENDING_RENDER.

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


setPlayingBackwardState​

<instance> setPlayingBackwardState()​

Description:

Sets this TweenData state to PLAYING_BACKWARD.

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


setPlayingForwardState​

<instance> setPlayingForwardState()​

Description:

Sets this TweenData state to PLAYING_FORWARD.

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


setRepeatState​

<instance> setRepeatState()​

Description:

Sets this TweenData state to REPEAT_DELAY.

Source: src/tweens/tween/BaseTweenData.js#L313
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:

nametypeoptionaldescription
diffnumberNoAny 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

Source: src/tweens/tween/BaseTweenData.js#L441
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:

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

Fires: Phaser.Tweens.Events#event:TWEEN_REPEAT

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


setTargetValue​

<instance> setTargetValue([value])​

Description:

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

Parameters:

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

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