Skip to content

Animated Textures

SpiDrone edited this page Jul 22, 2026 · 2 revisions

Animated Textures

UIAnimationManager draws frame by frame animations from a vertical sprite sheet, basically a lightweight gif player for your GUI built from a single PNG with frames stacked on top of each other.

Preparing a Sprite Sheet

Your texture needs to be one column of equally sized frames stacked vertically, in playback order top to bottom:

assets/<namespace>/textures/gui/anim_fire.png

If each frame is 32x32 and you have 8 frames, the full file is 32px wide by 256px tall.

Basic Usage

UIAnimationManager.drawGif(
    graphics,
    "mymod:textures/gui/anim_fire.png",
    x, y,
    32, 32,   // frame width, frame height
    8,        // total frames
    12        // frames per second
);

This loops on its own for as long as you keep drawing it, since the current frame is worked out from the system clock every call. There's no separate start call, just call it every render tick from your screen or overlay same as any other GuiGraphics draw.

Scaling and Color Tinting

The full method also takes scale and RGB tint multipliers:

UIAnimationManager.drawGif(
    graphics,
    "mymod:textures/gui/anim_fire.png",
    x, y,
    32, 32,   // frame width, frame height
    8,        // total frames
    12,       // fps
    2.0F, 2.0F,   // scaleX, scaleY, draws the animation at double size
    1.0F, 0.6F, 0.6F  // red, green, blue tint multipliers, 0.0 to 1.0 each
);
Param Meaning
scaleX / scaleY Size multipliers. 1.0F is original size, 2.0F is double, 0.5F is half
red / green / blue Tint multipliers from 0.0F to 1.0F. 1.0F, 1.0F, 1.0F is untinted

Tinting multiplies against whatever colors are already in the texture rather than replacing them, so 1.0F, 0.6F, 0.6F gives a warm red tint on a normally white or grey sprite, while a fully white sprite tinted 1.0F, 0.0F, 0.0F comes out pure red.

Example: Status Icon

// A 16x16 pulsing icon, 6 frames at 10fps, drawn at double size
UIAnimationManager.drawGif(graphics, "mymod:textures/gui/icon_pulse.png",
    x, y, 16, 16, 6, 10, 2.0F, 2.0F, 1.0F, 1.0F, 1.0F);

Notes

  • Texture paths get cached after the first draw call, so repeated calls with the same path string don't re-parse the ResourceLocation every frame. Safe to call every tick without doing your own caching.
  • If totalFrames or fps is 0 or negative, the call just gets skipped instead of throwing. Handy if you're driving those from config and want a safe disabled state.
  • If the texture path can't be resolved, the call also gets skipped quietly instead of crashing your GUI. If nothing draws, check your resource pack paths first.

Clone this wiki locally