AnimationHelpers
AnimationHelpers are a set of classes provided by DynamicHUD that helps implementing simple and recurrent animations.
Here is a short description of each of them:
AnimationProperty
Defines a property that holds and updates a value for animations.
Purpose: Provides getter and setter for animatable values.
Key Methods:
get()
: Returns the current value.set(T)
: Updates the value.
Example:
AnimationProperty<Float> opacity = new AnimationProperty<>() { private float value = 1.0f; public Float get() { return value; } public void set(Float v) { value = v; } };
Animation
Abstract base class for animations, managing timing and progress.
Purpose: Handles animation lifecycle (start, update, stop) with easing and callbacks.
Key Methods:
start()
: Begins the animation.update()
: Updates animation state.duration(long)
: Sets duration in milliseconds.easing(EasingType)
: Sets easing type.onComplete(Runnable)
: Adds callback when finished.
Example:
Animation anim = new ValueAnimation(opacity, 0.0f, 1.0f).duration(1000).easing(EasingType.EASE_OUT_SINE); anim.start();
Common Issue: Forgetting to call
update
regularly causes animations to stall.
Fix: Call
update
in the render loop.
ValueAnimation
Animates a float value from start to end using a property.
Purpose: Smoothly transitions a float value with easing.
Key Methods:
startValue(float)
: Sets starting value.endValue(float)
: Sets ending value.easing(EasingType)
: Sets easing type.getValue()
: Returns current value.
Example:
ValueAnimation fade = new ValueAnimation(opacity, 0.0f, 1.0f, EasingType.EASE_IN_OUT_SINE).duration(500); fade.start();
Warning: Ensure the
AnimationProperty
is valid to avoid runtime errors.
CompositeAnimation
Combines multiple animations to run sequentially or in parallel.
Purpose: Groups animations for coordinated effects.
Key Methods:
add(Animation)
: Adds an animation to the group.start()
: Starts all animations (parallel or sequential).stop()
: Stops all animations.
Example:
CompositeAnimation group = new CompositeAnimation(true); // Parallel group.add(new ValueAnimation(opacity, 0.0f, 1.0f).duration(500)); group.add(new ValueAnimation(scale, 1.0f, 1.5f).duration(500)); group.start();
Common Issue: Sequential animations may not start if durations are miscalculated.
Fix: Verify each child’s duration is set correctly.
EasingType
Enum listing easing functions for animation curves.
Purpose: Defines how animation progress is interpolated (e.g., linear, bounce).
Key Values:
LINEAR
: Constant speed.EASE_IN_SINE
: Slow start, fast end.EASE_OUT_BOUNCE
: Bouncing effect at end.
Example:
animation.easing(EasingType.EASE_IN_OUT_QUAD);
Easing
Applies easing functions to animation progress.
Purpose: Transforms linear progress into smooth curves based on
EasingType
.Key Method:
apply(EasingType, float)
: Returns eased progress (0.0 to 1.0).
Example:
float eased = Easing.apply(EasingType.EASE_OUT_SINE, 0.5f);
MathAnimations
Utility class for procedural animation effects.
Purpose: Provides standalone animation functions (e.g., shake, pulse).
Docs:
/// SHAKE: Random offset animation with smooth decay
public static float shake(float intensity, float frequency, float decay)
/// 2D Shake with different X/Y frequencies
public static Vec2f shake2D(float intensity, float freqX, float freqY
/// FLICKER: Random flashing effect
public static float flicker(float min, float max, float chance)
/// CIRCULAR MOTION: Perfect for rotation/orbital animations
public static Vec2f circularMotion(float radius, float speed, float phase)
/// SAWTOOTH WAVE: Linear rise with sudden drop
public static float sawtooth(float period, float min, float max)
/// TRIANGULAR WAVE: Linear rise and fall
public static float triangleWave(float period, float min, float max)
/// BOUNCE: Simulates physical bouncing
public static float bounce(float dropHeight, float gravity, float dampening)
/// PULSE: Smooth heartbeat-like effect
public static float pulse1(float base, float amplitude, float frequency)
/// SPIRAL: Circular motion with expanding radius
public static Vec2f spiral(float baseRadius, float expansionRate, float speed)
/// Continuous pulsating effect using sine wave
public static float pulse2(float speed, float min, float max)
/// Linear interpolation between values over time
public static float lerp(float start, float end, long startTime, float duration)
/// Linear interpolation between values over time with easing
public static float lerp(float start, float end, long startTime, float duration, EasingType easing)
/// Bouncing animation using quadratic ease-out
public static float bounce(float start, float end, long startTime, float duration)
/// Continuous rotation using modulo
public static float continuousRotation(float speed)
/// Elastic wobble effect
public static float elasticWobble(float speed, float magnitude)
}
Example:
float offset = MathAnimations.shake(5.0f, 0.1f, 0.001f); // Shaky effect
Common Issue: Using high-intensity values can cause visual glitches.
Fix: Test with small values (e.g., intensity < 10).
Last updated
Was this helpful?