Skip to content

BaseTween

abstract class BaseTween<T extends BaseTween<T>>
Known subtypes: Timeline, Tween
Package: dev.joid.lib.animation.tween · Module: core · Source: BaseTween.java

Shared state and timing of a tween and a timeline: delay, repetitions, pause, events and the advance in time.

A Tween or a Timeline does nothing by itself: something advances it with update(delta), in milliseconds. A TweenAnimator advances its timeline once per frame; a TweenManager advances what it holds when you update it; code of your own can call update(...) itself. A negative delta plays backward.

ReturnsSignatureSummary
BaseTween() protectedCreates a tween that is not started, for a subclass.

ReturnsSignatureSummary
floatgetFullDuration()Returns the delay, every play and every repeat delay added together, in ms, or -1F for a repetition forever.
booleanisFinished()If true, the last play ended or the tween was killed.
floatgetDelay()Returns the delay in ms.
booleanisYoyo()If true, every other play runs backward.
intgetRepeatCount()Returns the number of plays after the first, or INFINITY.
floatgetDuration()Returns the length of one play in ms.
floatgetRepeatDelay()Returns the time between two plays in ms.
intgetStep()Returns the position in the plays: negative before the start, an even number during a play, an odd number between two plays.
booleanisPaused()If true, updates do not advance the tween.
floatgetCurrentTime()Returns the time in ms spent in the current play or wait.
booleanisStarted()If true, start() was called.
booleanisInitialized()If true, the delay elapsed and the tween read its start values.
ObjectgetUserData()Returns the object given to userData(...), or null.
ReturnsSignatureSummary
Tstart()Builds the tween and places it at its beginning, then returns it; the next updates play it.
Tstart(TweenManager manager)Adds the tween to manager, which starts it, then returns it.
Tbuild()Fixes the children and the duration of a timeline, then returns it; start() calls it.
Tkill()Stops the tween and its children for good, then returns it; isFinished() becomes true.
Tpause()Freezes the tween, then returns it.
Tresume()Lets updates advance the tween again, then returns it.
Tdelay(float delay)Adds delay ms before the first play, then returns the tween.
Trepeat(int count, float delay)Plays the tween count more times after the first, with delay ms between two plays, then returns it; a negative delay counts as 0.
TrepeatYoyo(int count, float delay)Repeats like repeat(...), every other play backward, then returns the tween.
TuserData(Object userData)Attaches an object of your own to the tween, then returns it.
TforceToStart()Puts the tween before its first play and applies its start values, then returns it.
TforceToEnd(float time)Puts the tween after its last play and applies its end values, then returns it; time is the time already spent past the end.
voidupdate(float delta)Advances the tween by delta ms, backward when delta is negative, firing the events it crosses.
ReturnsSignatureSummary
booleanisValid(int step) protectedIf true, step is within the plays of the tween.
booleanisReverse(int step) protectedIf true, the play at step runs backward in a yoyo.
voidkillChildren() hook protectedKills the children; a timeline overrides it.
voidstartChildren() hook protectedStarts the children; a timeline overrides it.
voidbuildChildren() hook protectedBuilds the children; a timeline overrides it.
voidinitializeValues() hook protectedReads the start values when the delay ends.
voidupdateValues(int step, int lastStep, boolean isIterationStep, float delta) hook protectedApplies the values for the time reached, after each advance.
voidforceStartValues() hook abstract protectedApplies the values of the beginning of a play.
voidforceEndValues() hook abstract protectedApplies the values of the end of a play.

EventListenerSummary
onStartEventListener<TweenEvent>Adds a listener that runs when the first play starts, after the delay.
onIterationStartEventListener<TweenEvent>Adds a listener that runs at the start of each play.
onIterationEndEventListener<TweenEvent>Adds a listener that runs at the end of each play.
onCompleteEventListener<TweenEvent>Adds a listener that runs when the last play ends; it never runs for a repetition forever.
onReverseStartEventListener<TweenEvent>Adds a listener that runs when the tween starts playing backward from its end.
onReverseIterationStartEventListener<TweenEvent>Adds a listener that runs at the start of each play backward.
onReverseIterationEndEventListener<TweenEvent>Adds a listener that runs at the end of each play backward.
onReverseCompleteEventListener<TweenEvent>Adds a listener that runs when the tween played backward reaches its beginning.
TypeNameValueSummary
intINFINITY-1Repeat count that repeats forever (-1).
floatdelayThe time in ms before the first play; delay(...) adds to it.
floatdurationThe length of one play in ms; a timeline computes it from its children when it is built.

BaseTween() protected

Creates a tween that is not started, for a subclass.

float getFullDuration()

Returns the delay, every play and every repeat delay added together, in ms, or -1F for a repetition forever.

boolean isFinished()

If true, the last play ended or the tween was killed.

float getDelay()

Returns the delay in ms.

boolean isYoyo()

If true, every other play runs backward.

int getRepeatCount()

Returns the number of plays after the first, or INFINITY.

float getDuration()

Returns the length of one play in ms.

float getRepeatDelay()

Returns the time between two plays in ms.

int getStep()

Returns the position in the plays: negative before the start, an even number during a play, an odd number between two plays.

boolean isPaused()

If true, updates do not advance the tween.

float getCurrentTime()

Returns the time in ms spent in the current play or wait.

boolean isStarted()

If true, start() was called.

boolean isInitialized()

If true, the delay elapsed and the tween read its start values.

Object getUserData()

Returns the object given to userData(...), or null.

T start()

Throws:

  • IllegalStateException: A tween or timeline that repeats forever needs a duration or a repeat delay above 0, give it one or a finite repeat count

Builds the tween and places it at its beginning, then returns it; the next updates play it. Throws an IllegalStateException for a repetition forever whose duration and repeat delay are both 0.

T start(TweenManager manager)

Adds the tween to manager, which starts it, then returns it.

T build()

Fixes the children and the duration of a timeline, then returns it; start() calls it.

T kill()

Stops the tween and its children for good, then returns it; isFinished() becomes true. Killed from one of its own listeners, it stops within the same update.

T pause()

Freezes the tween, then returns it.

T resume()

Lets updates advance the tween again, then returns it.

T delay(float delay)

Adds delay ms before the first play, then returns the tween.

T repeat(int count, float delay)

Plays the tween count more times after the first, with delay ms between two plays, then returns it; a negative delay counts as 0. Throws an IllegalStateException once the tween is started.

T repeatYoyo(int count, float delay)

Repeats like repeat(...), every other play backward, then returns the tween.

T userData(Object userData)

Attaches an object of your own to the tween, then returns it.

T forceToStart()

Puts the tween before its first play and applies its start values, then returns it.

T forceToEnd(float time)

Puts the tween after its last play and applies its end values, then returns it; time is the time already spent past the end.

void update(float delta)

Advances the tween by delta ms, backward when delta is negative, firing the events it crosses. It does nothing before start(), while paused or once killed.

boolean isValid(int step) protected

If true, step is within the plays of the tween.

boolean isReverse(int step) protected

If true, the play at step runs backward in a yoyo.

void killChildren() hook protected

Kills the children; a timeline overrides it.

void startChildren() hook protected

Starts the children; a timeline overrides it.

void buildChildren() hook protected

Builds the children; a timeline overrides it.

void initializeValues() hook protected

Reads the start values when the delay ends.

void updateValues(int step, int lastStep, boolean isIterationStep, float delta) hook protected

Applies the values for the time reached, after each advance.

void forceStartValues() hook abstract protected

Applies the values of the beginning of a play.

void forceEndValues() hook abstract protected

Applies the values of the end of a play.

T onStart(EventListener<TweenEvent> listener)

Adds a listener that runs when the first play starts, after the delay.

T onIterationStart(EventListener<TweenEvent> listener)

Adds a listener that runs at the start of each play.

T onIterationEnd(EventListener<TweenEvent> listener)

Adds a listener that runs at the end of each play.

T onComplete(EventListener<TweenEvent> listener)

Adds a listener that runs when the last play ends; it never runs for a repetition forever.

T onReverseStart(EventListener<TweenEvent> listener)

Adds a listener that runs when the tween starts playing backward from its end.

T onReverseIterationStart(EventListener<TweenEvent> listener)

Adds a listener that runs at the start of each play backward.

T onReverseIterationEnd(EventListener<TweenEvent> listener)

Adds a listener that runs at the end of each play backward.

T onReverseComplete(EventListener<TweenEvent> listener)

Adds a listener that runs when the tween played backward reaches its beginning.

int INFINITY

Repeat count that repeats forever (-1).

float delay protected

The time in ms before the first play; delay(...) adds to it.

float duration protected

The length of one play in ms; a timeline computes it from its children when it is built.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page