Skip to content
holydev edited this page Dec 3, 2026 · 2 revisions



Get Started

public class ExampleScreen extends Screen {
    public ExampleScreen() {
    }

    @Override
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
        AnimLib.update(this);
        /* 
         * Updates all active animations of the specified screen on the current frame
         * Without it, numerical animations created
         * via AnimationBuilder will not progress over time
        */
    }

    @Override
    public void onClose() {
        AnimLib.clear(this)
        /*
         * Clear registered animator in this screen
         * this method is important. Because this will
         * improve the optimization of your screen.
         */
        super.removed();
    }
}

AnimationBuilder

private float posX = 0F;

@Override
protected void init() {
    AnimLib.animate(this)
            .from(0F)
            .to(120F)
            .duration(0.8F)
            .easeInOut()
            .bind(value -> posX = value)
            .start();
}

Available parameters:
from(float) - Initial value
to(float) - Final value
duration(float) - Duration in seconds
delay(float) - Delays the start of the animation by a specified number of seconds
bind(Consumer<Float>)- The recipient of the new value
start() - Adds the configured animation
value(from, to, duration, setter) - Quickly adds a value without a separate start()
repeat(int) - The number of repetitions for the ONCE mode or the number of full cycles for PING_PONG
loop() - An endless cycle from beginning to end
pingPong() - Movement from the beginning to the end and back
easing(...) - Custom smoothness function

Animation modes

ONCE - the value goes from from to and stops
LOOP - after reaching the time, it returns to the beginning
PING_PONG - the value moves from from to to, then back to from
After ONCE is completed, the animation is removed from ScreenAnimator. Cyclic animations remain active as long as the screen exists or until its animator is cleared!

Synchronized animations

Starting with version 1.0.3, a new function is introduced that allows you to change an indefinite number of variables simultaneously. This is well‑suited for simultaneously changing the X and Y coordinates of an object’s position.

private float posX = 0F;
private float posY = 0F;

@Override
protected void init() {
    AnimLib.animate(this, 2) // In this case, the number 2 represents the quantity of variables
            .from(posX, posY)
            .to(120F, 120F)
            .duration(0.8F)
            .easeInOut()
            .bind(values -> {
                posX = values[0];
                posY = values[1];
            })
            .start();
}

AnimationHandle

Thanks to AnimationHandle, you can interact with animations more actively. It allows you to pause, cancel, or reset the animation. In addition, it can return boolean by reading the animation states.

public class ExampleScreen extends Screen {
    private Button moveButton;
    private AnimationHandle buttonAnimation;
    
    public ExampleScreen() {
    }

    @Override
    protected void init() {
        moveButton = Button.builder(Component.literal("Button"), button -> moveButton())
                .pos(0, 0)
                .size(60, 15)
                .build();
        addRenderableWidget(moveButton);
    }

    @Override
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
        AnimLib.update(this);
    }

    @Override
    public void onClose() {
        AnimLib.clear(this)
        super.removed();
    }

    private void moveButton(Button button, int targetX, int targetY) {
        if (buttonAnimation != null && buttonAnimation.isRunning()) {
            buttonAnimation.cancel();
        }

        buttonAnimation = AnimLib.animate(this, 2)
                .from(button.getX(), button.getY())
                .to(targetX, targetY)
                .duration(0.35f)
                .sineInOut()
                .bind(values -> {
                    int x = Math.round(values[0]);
                    int y = Math.round(values[1]);
                    button.setPosition(x, y);
                })
                .startHandle();
    }
}

AnimationHandle functions:
pause() - pauses the animation
resume() - resumes the animation playback
cancel() - cancels the animation
reset() - resets the animation

isRunning() - checks if the animation is running
isPaused() - checks if the animation is paused
isFinished() - checks if the animation is finished
isCancelled() - checks if the animation has been cancelled

Sequence

A function that will allow you to start the next animation only after the previous one has finished.

AnimLib.sequence(this)
        .then(animation -> animation
                .from(0f)
                .to(1f)
                .duration(0.2f)
                .sineOut()
                .bind(value -> panelAlpha = value)
        )
        .then(2, animation -> animation
                .from(startX, startY)
                .to(targetX, targetY)
                .duration(0.35f)
                .backOut()
                .bind(values -> button.setPosition(
                        Math.round(values[0]),
                        Math.round(values[1])
                ))
        )
        .start();

Inside .then(...), you don’t need to write .start(): the library automatically starts the step at the right moment.

Stagger

The function allows you to sequentially run animations with a certain delay for each object.
Example: each button starts moving 0.08 seconds later than the previous one.

List<Button> buttons = List.of(firstButton, secondButton, thirdButton);

AnimLib.stagger(this, buttons, 0.08f)
        .start((button, animation) -> {
            int targetY = button.getY();

            animation
                    .from(targetY - 20f)
                    .to(targetY)
                    .duration(0.25f)
                    .sineOut()
                    .bind(value -> button.setY(Math.round(value)));
        });

For several parameters, each element:

AnimLib.stagger(this, buttons, 0.08f)
        .startMulti(2, (button, animation) -> animation
                .from(button.getX() - 20f, button.getY())
                .to(button.getX(), button.getY())
                .duration(0.25f)
                .sineOut()
                .bind(values -> button.setPosition(
                        Math.round(values[0]),
                        Math.round(values[1])
                ))
        );

Easing / smoothness curves

linear() - uniform movement
easeIn() / cubicIn() - slow start, quick finish
easeOut() / cubicOut() - quick start, soft stop
easeInOut() - smooth start and smooth stop
sineIn() - soft start on a sine curve
sineOut() - soft finish on a sine curve
sineInOut() - sine smoothness on both sides
quadIn() / quadOut() / quadInOut() - quadratic curve, softer than cubic
backIn() - slightly pulls back before starting
backOut() - slightly overshoots the target and returns
elasticOut() - bouncy approach to the target
bounceIn() / bounceOut() - simulates a bounce

The names are slightly different, but the essence is clear... In addition, you can delegate your function:

.easing(progress -> progress * progress * progress)

The input and return values of the function represent progress from 0 to 1.


---

# Animated text

`AnimLib.drawText(...)` allows you to draw text using `AnimEffects`. The function draws letter by letter. The effects are applied in order, and they can be combined.

```java
AnimLib.drawText(graphics, font, "Cookies!",
        x, y,
        0xFFFFFF, true,
        AnimEffects.wave(3f, 1.2f, 0.45f),
        AnimEffects.rainbow(0.12f, 0.06f)
);

AnimLib.drawText(...) is capable of accepting Component to preserve Style.
Besides drawText(...) there are similar functions, but they are responsible for the position of the text. For example, drawCenteredText(...), which places the text in the center (similar in its operation to guiGraphics#drawCenteredString') or drawTextBlock(...) for multi-line text.

AnimEffects

wave(float amplitude, float speed, float spacing) - a sinusoidal wave along the vertical axis
bounce(float amplitude, float speed, float spacing) - each letter bounces
shake(float amplitude, float speed) - controlled tremor along X and Y
wiggle(float amplitude, float speed, float spacing) - oscillation along an individual direction
swing(float angle, float speed, float spacing) - the letters sway around the center
pendulum(float angle, float radius, float speed) - pendulum: rotation and, optionally, circular displacement
turbulence(float amplitude, float speed) - uneven organic movement
glitch(float frequency) - glitch with rare jerks and blinking
glitch(float frequency, float jitterChance, float blinkChance) - a customizable glitch variant
fade(float minAlpha, float speed, float spacing) - soft transparency pulsation
pulse(float minAlpha, float speed, float spacing) - transparency pulsation
rainbow(float speed, float spacing) - running HSV rainbow color
gradient(int fromColor, int toColor, float speed) - gradient between two RGB colors
scalePulse(float min, float max, float speed, float spacing) - pulsating scale
Amplitude is usually measured in pixels, angle in degrees, speed sets the rate of change, and spacing shifts the phase between adjacent letters.
On 1.21.1, the gradient runs from the first color to the second and back, without a sudden color drop at the cycle boundary.

word(AnimEffect effect) - helps to combine one animation for an entire word, rather than letter by letter as is the default
line(AnimEffect effect) - combines the animation for a single line. The animation is split after \n
block(AnimEffect effect) - combines the animation for the entire text block

typeWriter(float unitsPerSecond) - types the text letter by letter
reveal(float unitsPerSecond) - smoothly reveals the text letter by letter
dissolve(float unitsPerSecond) — gradually reveals the text in a random order
Due attention should be paid to the fact that typeWriter(...), reveal(...) and dissolve(...) should be called only once, since these are one‑time effects.
Example:

public class TestScreen extends Screen {
    private static final int TEXT_COLOR = 0xD9CAD5;
    
    private final AnimEffect typewriter = AnimEffects.typewriter(1.2f);
    private final AnimEffect reveal = AnimEffects.reveal(1.2f);
    private final AnimEffect dissolve = AnimEffects.dissolve(1.2f);

    @Override
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
        super.render(graphics, mouseX, mouseY, partialTick);

        int left = width / 2;
        int top = 28;

        AnimLib.drawText(graphics, font, "Sample text", left, top + 216, TEXT_COLOR, true, typewriter);
        AnimLib.drawText(graphics, font, "Sample text", left, top + 234, TEXT_COLOR, true, reveal);
        AnimLib.drawText(graphics, font, "Sample text", left, top + 252, TEXT_COLOR, true, dissolve);
    }
}

Creating your own AnimEffect

public final class SwingOffsetEffect implements AnimEffect {
    private final float rotationDegrees;
    private final float horizontalOffset;
    private final float speed;
    private final float glyphSpacing;

    public SwingOffsetEffect(float rotationDegrees, float horizontalOffset, float speed, float glyphSpacing) {
        this.rotationDegrees = rotationDegrees;
        this.horizontalOffset = horizontalOffset;
        this.speed = speed;
        this.glyphSpacing = glyphSpacing;
    }

    @Override
    public void apply(TextRenderState state, TextEffectContext context) {
        float phase = context.getTime() * speed + context.getGlyphIndex() * glyphSpacing;

        state.rotate((float) Math.sin(phase) * rotationDegrees);
        state.moveX((float) Math.cos(phase) * horizontalOffset);
    }
}

Example of usage in the Screen:

public class CustomEffectScreen extends Screen {
    private static final SwingOffsetEffect EFFECT = new SwingOffsetEffect(10f, 2f, 1f, 0.15f);

    public CustomEffectScreen() {
        super(Component.literal("Effect example"));
    }

    @Override
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
        renderBackground(graphics, mouseX, mouseY, partialTick);

        AnimLib.drawText(
                graphics, 
                font, 
                "Animated text",
                width / 2 - 50, height / 2,
                0xFFFFFF, true, 
                EFFECT
        );

        super.render(graphics, mouseX, mouseY, partialTick);
    }
}

# Texture animation

`AnimLib.blit(...)` applies the same spatial effects to the texture: offset, scale, rotation, and transparency.

```java
@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
    AnimLib.update(this);
    
    AnimLib.blit(graphics, texture, x, y, width, height, effects);
    
    AnimLib.blit(
            graphics,
            MY_TEXTURE,
            20, 20,
            32, 32,
            AnimEffects.scalePulse(0.9f, 1.1f, 1f, 0f)
    );
    // the second one is intended for rendering part of the texture from the atlas

    super.render(graphics, mouseX, mouseY, partialTick);
}