Class Smooth

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

public final class Smooth extends Object
A value that glides towards a target with exponential damping, the same at any frame rate. Good for things whose target moves every frame: a slider knob, a health bar, a scroll offset.
Smooth health = new Smooth(12);   // 12 per second: closes about 63% of the gap in 1/12 s
health.target(player.health());
float shown = health.update();
  • Constructor Summary

    Constructors
    Constructor
    Description
    Smooth(double ratePerSecond)
    Creates a smoothed value at 0, using the system clock.
    Smooth(double ratePerSecond, Clock clock)
    Creates a smoothed value at 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    snap(double v)
    Jumps to a value and rests there.
    double
    Returns the target.
    target(double target)
    Sets where the value is heading.
    float
    Advances to now and returns the value.
    double
    Returns the value without advancing.

    Methods inherited from class Object

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

    • Smooth

      public Smooth(double ratePerSecond)
      Creates a smoothed value at 0, using the system clock.
      Parameters:
      ratePerSecond - how quickly it closes the gap; higher is snappier
    • Smooth

      public Smooth(double ratePerSecond, Clock clock)
      Creates a smoothed value at 0.
      Parameters:
      ratePerSecond - how quickly it closes the gap
      clock - the time source
  • Method Details

    • target

      public Smooth target(double target)
      Sets where the value is heading.
      Parameters:
      target - the target
      Returns:
      this
    • snap

      public Smooth snap(double v)
      Jumps to a value and rests there.
      Parameters:
      v - the value
      Returns:
      this
    • update

      public float update()
      Advances to now and returns the value. Call once per frame.
      Returns:
      the current value
    • value

      public double value()
      Returns the value without advancing.
      Returns:
      the value at the last update
    • target

      public double target()
      Returns the target.
      Returns:
      the target