Package yearreview.app.animation
Class AnimatedNumber
java.lang.Object
java.lang.Number
yearreview.app.animation.AnimatedNumber
- All Implemented Interfaces:
Serializable
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 Summary
Modifier and TypeFieldDescriptionprivate float
Value at the end of the animation.private float
Value at the start of the animation.private AnimationCurve
Curve used for the animation.private final AnimationCurve
Default curve used for animations if no curve is specified.private int
Remaining duration of the currently running animation in milliseconds.private int
Total duration of the currently running animation in milliseconds.private float
Current value of this number. -
Constructor Summary
ConstructorDescriptionAnimatedNumber
(float initialVal) Constructs an AnimatedNumber from a starting value and withAnimationCurve.EASE_IN_OUT
as the defaultAnimationCurve
.AnimatedNumber
(float initialVal, AnimationCurve defaultCurve) Constructs an AnimatedNumber from a starting value and AnimationCurve. -
Method Summary
Modifier and TypeMethodDescriptionvoid
animateTo
(float newValue) Animates the value to a given new value.void
Animates the value to a given new value with a certain animation duration.void
animateTo
(float newValue, Duration d, AnimationCurve c) Animated the value to a given new value with a certain animation duration and AnimationCurve.double
Gets the animation value as a double.float
Gets the animation value as a float.int
intValue()
Gets the animation value as an integer.long
Gets the animation value as a long.private static float
map
(float val, float min, float max) Maps a value in the interval [0, 1] to the interval [min, max].protected boolean
updateAnimation
(int deltaTimeMs) Updates the animations by a given time that has passed since the last update.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
value
private float valueCurrent value of this number. -
animationStart
private float animationStartValue at the start of the animation. -
animationEnd
private float animationEndValue at the end of the animation. -
curve
Curve used for the animation. -
defaultCurve
Default curve used for animations if no curve is specified. -
totalAnimationDurationMs
private int totalAnimationDurationMsTotal duration of the currently running animation in milliseconds. -
remainingAnimationDurationMs
private int remainingAnimationDurationMsRemaining duration of the currently running animation in milliseconds.
-
-
Constructor Details
-
AnimatedNumber
public AnimatedNumber(float initialVal) Constructs an AnimatedNumber from a starting value and withAnimationCurve.EASE_IN_OUT
as the defaultAnimationCurve
.- Parameters:
initialVal
- initial Value of the AnimatedNumber
-
AnimatedNumber
Constructs an AnimatedNumber from a starting value and AnimationCurve.- Parameters:
initialVal
- initial Value of the AnimatedNumberdefaultCurve
- curve to use for animations if no curve is specified (has to benormalized
)
-
-
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. UsesGlobalSettings.getAnimationDuration()
to get the duration of the animation.- Parameters:
newValue
- new value to animate to
-
animateTo
Animates the value to a given new value with a certain animation duration.- Parameters:
newValue
- new value to animate tod
- duration of the animation to the new value
-
animateTo
Animated the value to a given new value with a certain animation duration and AnimationCurve.- Parameters:
newValue
- new value to animate tod
- duration of animation to the new valuec
- curve to use for the animation to the new value (has to benormalized
)
-
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 mapmin
- minimum value of the intervalmax
- maximum value of the interval- Returns:
- mapped value
-
intValue
public int intValue()Gets the animation value as an integer. Consider usingfloatValue()
instead since the value is represented as a float internally. -
longValue
public long longValue()Gets the animation value as a long. Consider usingfloatValue()
instead since the value is represented as a float internally. -
floatValue
public float floatValue()Gets the animation value as a float.- Specified by:
floatValue
in classNumber
- Returns:
- float
-
doubleValue
public double doubleValue()Gets the animation value as a double. Consider usingfloatValue()
instead since the value is represented as a float internally.- Specified by:
doubleValue
in classNumber
- Returns:
- double
-