Class Animation

java.lang.Object
lol.trq.helios.anim.Animation

public final class Animation extends Object
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
    Constructor
    Description
    Animation(long durationMillis, Easing easing)
    Creates an animation at rest at 0, using the system clock.
    Animation(long durationMillis, Easing easing, Clock clock)
    Creates an animation at rest at 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    between(float from, float to)
    Interpolates between two values by value().
    boolean
    Returns whether the animation has reached the end it is heading to.
    void
    duration(long durationMillis)
    Changes the duration of a full run, keeping the current position.
    boolean
    Returns the direction.
    forward(boolean towardsOne)
    Sets the direction: towards 1 when true, towards 0 when false.
    double
    Returns the linear progress.
    Restarts from 0 towards 1.
    snap(boolean atOne)
    Jumps to an end and rests there.
    Reverses the direction.
    double
    Returns the eased value.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Animation

      public Animation(long durationMillis, Easing easing)
      Creates an animation at rest at 0, using the system clock.
      Parameters:
      durationMillis - how long a full 0-to-1 run takes
      easing - the curve
    • Animation

      public Animation(long durationMillis, Easing easing, Clock clock)
      Creates an animation at rest at 0.
      Parameters:
      durationMillis - how long a full 0-to-1 run takes
      easing - the curve
      clock - the time source
  • Method Details

    • forward

      public Animation forward(boolean towardsOne)
      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

      public Animation toggle()
      Reverses the direction.
      Returns:
      this animation
    • snap

      public Animation snap(boolean atOne)
      Jumps to an end and rests there.
      Parameters:
      atOne - rest at 1 when true, at 0 when false
      Returns:
      this animation
    • restart

      public Animation restart()
      Restarts from 0 towards 1.
      Returns:
      this animation
    • 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 by value().
      Parameters:
      from - the value at 0
      to - 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