Class Animation
java.lang.Object
lol.trq.helios.anim.Animation
A timed transition between 0 and 1 that can be reversed at any moment without jumping.
Typical use: a menu that opens and closes. Call forward(boolean) with whether it should be open, and draw
with value(). Reversing halfway continues from the current position, taking half the duration to get back.
Animation open = new Animation(250, Easing.CUBIC_OUT);
open.forward(menuOpen);
float scale = (float) open.value();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatbetween(float from, float to) Interpolates between two values byvalue().booleandone()Returns whether the animation has reached the end it is heading to.voidduration(long durationMillis) Changes the duration of a full run, keeping the current position.booleanforward()Returns the direction.forward(boolean towardsOne) Sets the direction: towards 1 when true, towards 0 when false.doubleprogress()Returns the linear progress.restart()Restarts from 0 towards 1.snap(boolean atOne) Jumps to an end and rests there.toggle()Reverses the direction.doublevalue()Returns the eased value.
-
Constructor Details
-
Animation
Creates an animation at rest at 0, using the system clock.- Parameters:
durationMillis- how long a full 0-to-1 run takeseasing- the curve
-
Animation
-
-
Method Details
-
forward
Sets the direction: towards 1 when true, towards 0 when false. Does nothing if it already goes that way.- Parameters:
towardsOne- the direction- Returns:
- this animation
-
toggle
-
snap
Jumps to an end and rests there.- Parameters:
atOne- rest at 1 when true, at 0 when false- Returns:
- this animation
-
restart
-
duration
public void duration(long durationMillis) Changes the duration of a full run, keeping the current position.- Parameters:
durationMillis- the new duration
-
progress
public double progress()Returns the linear progress.- Returns:
[0, 1]
-
value
public double value()Returns the eased value. Going towards 0 replays the curve backwards, so a menu closes the way it opened.- Returns:
- the eased progress
-
between
public float between(float from, float to) Interpolates between two values byvalue().- Parameters:
from- the value at 0to- the value at 1- Returns:
- the current value
-
done
public boolean done()Returns whether the animation has reached the end it is heading to.- Returns:
- true at rest
-
forward
public boolean forward()Returns the direction.- Returns:
- true when heading towards 1
-