Skip to content

AnimationTexture

Since 2.2.1

AnimationTexture plays a frame animation from a uniform sprite sheet — a PNG image arranged as a grid of equal-sized cells. The animation advances at a configurable speed and loops between a from and to frame index.

Registry name: animation_texture

INFO

Extends TransformTexture — supports rotate(), scale(), transform().


Usage

java
// 8×8 grid of 8 px cells, frames 32–44, advance every 1 tick
IGuiTexture anim = new AnimationTexture("mymod:textures/gui/particles.png")
    .setCellSize(8)
    .setAnimation(32, 44)   // from frame 32 to frame 44
    .setAnimation(1);       // 1 tick per frame

// Tinted animation
IGuiTexture tinted = new AnimationTexture("mymod:textures/gui/glow.png")
    .setCellSize(4)
    .setAnimation(0, 15)
    .setAnimation(2)
    .setColor(0xFF44AAFF);

How the Grid Works

The sprite sheet is divided into cellSize × cellSize equal-sized cells arranged left-to-right, top-to-bottom. Frame n is at column n % cellSize, row n / cellSize.

For example, with cellSize = 8:

  • Frame 0 → column 0, row 0
  • Frame 7 → column 7, row 0
  • Frame 8 → column 0, row 1

Fields

NameTypeDescription
imageLocationResourceLocationPath to the sprite sheet PNG.
cellSizeintNumber of cells per row/column. The sheet is cellSize × cellSize cells.
fromintFirst frame index (inclusive).
tointLast frame index (inclusive).
animationintGame ticks to display each frame before advancing.
colorintARGB tint colour. Default: -1 (white).

Methods

MethodReturnsDescription
setTexture(String)AnimationTextureChanges the sprite sheet image.
setCellSize(int)AnimationTextureSets the grid dimension (cells per row/column).
setAnimation(int from, int to)AnimationTextureSets the frame range and resets to the first frame.
setAnimation(int animation)AnimationTextureSets the ticks-per-frame speed.
setColor(int)AnimationTextureSets the ARGB tint colour.
copy()AnimationTextureReturns a deep copy.

Released under the MIT License.