Class AnimatedNumber

java.lang.Object
java.lang.Number
yearreview.app.animation.AnimatedNumber
All Implemented Interfaces:
Serializable

public class AnimatedNumber extends Number
A Number that is animated using an AnimationCurve. The animations are updated using the AnimationManager. Animations that have finished are automatically removed from the manager.
Author:
ColdStone37
See Also:
  • Field Details

    • value

      private float value
      Current value of this number.
    • animationStart

      private float animationStart
      Value at the start of the animation.
    • animationEnd

      private float animationEnd
      Value at the end of the animation.
    • curve

      private AnimationCurve curve
      Curve used for the animation.
    • defaultCurve

      private final AnimationCurve defaultCurve
      Default curve used for animations if no curve is specified.
    • totalAnimationDurationMs

      private int totalAnimationDurationMs
      Total duration of the currently running animation in milliseconds.
    • remainingAnimationDurationMs

      private int remainingAnimationDurationMs
      Remaining duration of the currently running animation in milliseconds.
  • Constructor Details

    • AnimatedNumber

      public AnimatedNumber(float initialVal)
      Constructs an AnimatedNumber from a starting value and with AnimationCurve.EASE_IN_OUT as the default AnimationCurve.
      Parameters:
      initialVal - initial Value of the AnimatedNumber
    • AnimatedNumber

      public AnimatedNumber(float initialVal, AnimationCurve defaultCurve)
      Constructs an AnimatedNumber from a starting value and AnimationCurve.
      Parameters:
      initialVal - initial Value of the AnimatedNumber
      defaultCurve - curve to use for animations if no curve is specified (has to be normalized)
  • Method Details

    • updateAnimation

      protected boolean updateAnimation(int deltaTimeMs)
      Updates the animations by a given time that has passed since the last update.
      Parameters:
      deltaTimeMs - time between updates
      Returns:
      true if the animation is finished and can be removed from the AnimationManager
    • animateTo

      public void animateTo(float newValue)
      Animates the value to a given new value. Uses GlobalSettings.getAnimationDuration() to get the duration of the animation.
      Parameters:
      newValue - new value to animate to
    • animateTo

      public void animateTo(float newValue, Duration d)
      Animates the value to a given new value with a certain animation duration.
      Parameters:
      newValue - new value to animate to
      d - duration of the animation to the new value
    • animateTo

      public void animateTo(float newValue, Duration d, AnimationCurve c)
      Animated the value to a given new value with a certain animation duration and AnimationCurve.
      Parameters:
      newValue - new value to animate to
      d - duration of animation to the new value
      c - curve to use for the animation to the new value (has to be normalized)
    • map

      private static float map(float val, float min, float max)
      Maps a value in the interval [0, 1] to the interval [min, max].
      Parameters:
      val - value to map
      min - minimum value of the interval
      max - maximum value of the interval
      Returns:
      mapped value
    • intValue

      public int intValue()
      Gets the animation value as an integer. Consider using floatValue() instead since the value is represented as a float internally.
      Specified by:
      intValue in class Number
      Returns:
      integer
    • longValue

      public long longValue()
      Gets the animation value as a long. Consider using floatValue() instead since the value is represented as a float internally.
      Specified by:
      longValue in class Number
      Returns:
      long
    • floatValue

      public float floatValue()
      Gets the animation value as a float.
      Specified by:
      floatValue in class Number
      Returns:
      float
    • doubleValue

      public double doubleValue()
      Gets the animation value as a double. Consider using floatValue() instead since the value is represented as a float internally.
      Specified by:
      doubleValue in class Number
      Returns:
      double