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:

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:

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:

Choose easing types to match the desired visual effect (e.g., EASE_OUT_BOUNCE for playful animations).

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:

Avoid using complex easing types like EASE_IN_OUT_ELASTIC for short animations to prevent unnatural motion.

MathAnimations

Utility class for procedural animation effects.

  • Purpose: Provides standalone animation functions (e.g., shake, pulse).

Docs:

  • Example:

Common Issue: Using high-intensity values can cause visual glitches.

  • Fix: Test with small values (e.g., intensity < 10).

Last updated

Was this helpful?