-
Notifications
You must be signed in to change notification settings - Fork 0
Animated Textures
UIAnimationManager draws frame-by-frame animations from a vertical sprite sheet — think of it as a lightweight "GIF" player for your GUI, built entirely from a single PNG texture with frames stacked on top of each other.
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 32×32 pixels and you have 8 frames, the full file is 32 px wide × 256 px tall.
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 plays the animation on a continuous loop for as long as it's drawn each render tick — there's no separate "start" call, since the current frame is calculated from the system clock every time it's drawn. Call it every frame from your screen/overlay's render method, same as any other GuiGraphics draw call.
The full method also accepts 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–1.0 each)
);
| Param | Meaning |
|---|---|
| scaleX / scaleY | Size multipliers. 1.0F = original size, 2.0F = double, 0.5F = half |
| red / green / blue | Tint multipliers from 0.0F to 1.0F. 1.0F, 1.0F, 1.0F = untinted |
Tinting multiplies against the texture's existing colors rather than replacing them, so 1.0F, 0.6F, 0.6F gives a warm red tint on a normally white/grey sprite, while a fully white sprite tinted 1.0F, 0.0F, 0.0F would come out pure red.
// A 16x16 pulsing icon, animated at 10fps across 6 frames, 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);
- Texture paths are cached internally after the first draw call, so repeated calls with the same path string don't re-parse the
ResourceLocationevery frame — safe to call every tick without a manual caching step on your end. - If
totalFramesorfpsis0or negative, the call is silently skipped rather than throwing — useful if you're driving those values from config and want a safe "disabled" state. - If the texture path can't be resolved (typo, missing file), the call is also silently skipped rather than crashing your GUI — check your resource pack paths if nothing draws.