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.
Description
Section titled “Description”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.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| BaseTween() protected | Creates a tween that is not started, for a subclass. |
Methods
Section titled “Methods”Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
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. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
T | start() | Builds the tween and places it at its beginning, then returns it; the next updates play it. |
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. |
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. |
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. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
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. |
Events
Section titled “Events”| Event | Listener | Summary |
|---|---|---|
| onStart | EventListener<TweenEvent> | Adds a listener that runs when the first play starts, after the delay. |
| onIterationStart | EventListener<TweenEvent> | Adds a listener that runs at the start of each play. |
| onIterationEnd | EventListener<TweenEvent> | Adds a listener that runs at the end of each play. |
| onComplete | EventListener<TweenEvent> | Adds a listener that runs when the last play ends; it never runs for a repetition forever. |
| onReverseStart | EventListener<TweenEvent> | Adds a listener that runs when the tween starts playing backward from its end. |
| onReverseIterationStart | EventListener<TweenEvent> | Adds a listener that runs at the start of each play backward. |
| onReverseIterationEnd | EventListener<TweenEvent> | Adds a listener that runs at the end of each play backward. |
| onReverseComplete | EventListener<TweenEvent> | Adds a listener that runs when the tween played backward reaches its beginning. |
Constants and fields
Section titled “Constants and fields”| Type | Name | Value | Summary |
|---|---|---|---|
int | INFINITY | -1 | Repeat count that repeats forever (-1). |
float | delay | The time in ms before the first play; delay(...) adds to it. | |
float | duration | The length of one play in ms; a timeline computes it from its children when it is built. |
Creation details
Section titled “Creation details”BaseTween
Section titled “BaseTween”BaseTween() protected
Creates a tween that is not started, for a subclass.
Method details
Section titled “Method details”getFullDuration
Section titled “getFullDuration”float getFullDuration()
Returns the delay, every play and every repeat delay added together, in ms, or -1F for a repetition forever.
isFinished
Section titled “isFinished”boolean isFinished()
If true, the last play ended or the tween was killed.
getDelay
Section titled “getDelay”float getDelay()
Returns the delay in ms.
isYoyo
Section titled “isYoyo”boolean isYoyo()
If true, every other play runs backward.
getRepeatCount
Section titled “getRepeatCount”int getRepeatCount()
Returns the number of plays after the first, or INFINITY.
getDuration
Section titled “getDuration”float getDuration()
Returns the length of one play in ms.
getRepeatDelay
Section titled “getRepeatDelay”float getRepeatDelay()
Returns the time between two plays in ms.
getStep
Section titled “getStep”int getStep()
Returns the position in the plays: negative before the start, an even number during a play, an odd number between two plays.
isPaused
Section titled “isPaused”boolean isPaused()
If true, updates do not advance the tween.
getCurrentTime
Section titled “getCurrentTime”float getCurrentTime()
Returns the time in ms spent in the current play or wait.
isStarted
Section titled “isStarted”boolean isStarted()
If true, start() was called.
isInitialized
Section titled “isInitialized”boolean isInitialized()
If true, the delay elapsed and the tween read its start values.
getUserData
Section titled “getUserData”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.
resume
Section titled “resume”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.
repeat
Section titled “repeat”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.
repeatYoyo
Section titled “repeatYoyo”T repeatYoyo(int count, float delay)
Repeats like repeat(...), every other play backward, then returns the tween.
userData
Section titled “userData”T userData(Object userData)
Attaches an object of your own to the tween, then returns it.
forceToStart
Section titled “forceToStart”T forceToStart()
Puts the tween before its first play and applies its start values, then returns it.
forceToEnd
Section titled “forceToEnd”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.
update
Section titled “update”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.
isValid
Section titled “isValid”boolean isValid(int step) protected
If true, step is within the plays of the tween.
isReverse
Section titled “isReverse”boolean isReverse(int step) protected
If true, the play at step runs backward in a yoyo.
killChildren
Section titled “killChildren”void killChildren() hook protected
Kills the children; a timeline overrides it.
startChildren
Section titled “startChildren”void startChildren() hook protected
Starts the children; a timeline overrides it.
buildChildren
Section titled “buildChildren”void buildChildren() hook protected
Builds the children; a timeline overrides it.
initializeValues
Section titled “initializeValues”void initializeValues() hook protected
Reads the start values when the delay ends.
updateValues
Section titled “updateValues”void updateValues(int step, int lastStep, boolean isIterationStep, float delta) hook protected
Applies the values for the time reached, after each advance.
forceStartValues
Section titled “forceStartValues”void forceStartValues() hook abstract protected
Applies the values of the beginning of a play.
forceEndValues
Section titled “forceEndValues”void forceEndValues() hook abstract protected
Applies the values of the end of a play.
Event details
Section titled “Event details”onStart
Section titled “onStart”T onStart(EventListener<TweenEvent> listener)
Adds a listener that runs when the first play starts, after the delay.
onIterationStart
Section titled “onIterationStart”T onIterationStart(EventListener<TweenEvent> listener)
Adds a listener that runs at the start of each play.
onIterationEnd
Section titled “onIterationEnd”T onIterationEnd(EventListener<TweenEvent> listener)
Adds a listener that runs at the end of each play.
onComplete
Section titled “onComplete”T onComplete(EventListener<TweenEvent> listener)
Adds a listener that runs when the last play ends; it never runs for a repetition forever.
onReverseStart
Section titled “onReverseStart”T onReverseStart(EventListener<TweenEvent> listener)
Adds a listener that runs when the tween starts playing backward from its end.
onReverseIterationStart
Section titled “onReverseIterationStart”T onReverseIterationStart(EventListener<TweenEvent> listener)
Adds a listener that runs at the start of each play backward.
onReverseIterationEnd
Section titled “onReverseIterationEnd”T onReverseIterationEnd(EventListener<TweenEvent> listener)
Adds a listener that runs at the end of each play backward.
onReverseComplete
Section titled “onReverseComplete”T onReverseComplete(EventListener<TweenEvent> listener)
Adds a listener that runs when the tween played backward reaches its beginning.
Constant and field details
Section titled “Constant and field details”INFINITY
Section titled “INFINITY”int INFINITY
Repeat count that repeats forever (-1).
float delay protected
The time in ms before the first play; delay(...) adds to it.
duration
Section titled “duration”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
