Skip to content

AnimatedTexture

Mutable sprite-sheet texture whose frame advances with game ticks, selected from a uniform cell grid.

Overview

AnimatedTexture divides a source sprite sheet into a uniform grid of cells, cycling through a defined range of frames based on game ticks without requiring widget update code.

Grid & Sizing

Cells are sized using setCellSize(width, height). Frames are numbered left-to-right, top-to-bottom across the sprite sheet columns.

Playback & Timing

Use setAnimation(from, to) to select an inclusive frame range (playing backwards if from > to) and setAnimation(ticksPerFrame) to control frame duration.

Basic Particle Sheet Animation

AnimatedTexture particles = new AnimatedTexture(sheet)
        .setCellSize(8)
        .setAnimation(32, 44)
        .setAnimation(1);
scope.texture(particles, x, y, 32.0f, 32.0f, Paint.NONE);
  • TextureHandle: Backend-neutral texture resource interface providing dimensions, sampling options, and native object access.
  • TextureRegion: Immutable UV sub-rectangle of a parent texture, used to draw sprites from texture atlases.

API

AnimatedTexture(String, int, int)

Constructs an animated texture from a resource ID and known sheet dimensions.

Parameter Type Description
id String The resource identifier string.
sheetWidth int The sprite sheet width in pixels.
sheetHeight int The sprite sheet height in pixels.

AnimatedTexture(TextureHandle)

Constructs an animated texture wrapping a sprite sheet texture handle.

Parameter Type Description
sheet TextureHandle The sprite sheet texture handle.

AnimatedTexture::base()

Returns the root physical texture handle resolving underlying sprite sheet storage.

Returns TextureHandle: The underlying base texture handle..

AnimatedTexture::cellHeight()

Returns the configured cell height in pixels.

Returns int: The cell height in pixels..

AnimatedTexture::cellWidth()

Returns the configured cell width in pixels.

Returns int: The cell width in pixels..

AnimatedTexture::currentFrame()

Returns the grid frame index corresponding to the current TextureClock tick.

Returns int: The calculated cell frame index..

AnimatedTexture::firstFrame()

Returns the first frame index of the animation sequence.

Returns int: The first frame index..

AnimatedTexture::frameAt(long)

Calculates the grid frame index for a specific absolute game tick.

Parameter Type Description
ticks long The absolute tick count.

Returns int: The calculated cell frame index..

AnimatedTexture::frameCount()

Returns the total number of frames in the active animation range.

Returns int: The total number of frames in range..

AnimatedTexture::frameUv(int, MutableRect)

Computes UV sub-rectangle coordinates within the sprite sheet for a given frame index.

Parameter Type Description
frame int The cell frame index.
out MutableRect The mutable rectangle receiving UV bounds.

AnimatedTexture::height()

Returns the visual cell height in pixels.

Returns int: The cell height in pixels..

AnimatedTexture::id()

Returns the texture resource ID delegated from the base sprite sheet.

Returns String: The texture identifier string..

AnimatedTexture::lastFrame()

Returns the last frame index of the animation sequence.

Returns int: The last frame index..

AnimatedTexture::nativeHandle()

Returns the low-level platform handle delegated from the parent sprite sheet.

Returns Object: The platform native texture handle..

AnimatedTexture::options()

Returns sampling options delegated from the parent sprite sheet.

Returns TextureOptions: The texture sampling options..

AnimatedTexture::resolveUv(MutableRect)

Resolves normalized UV coordinates for the current animated frame composed against base storage.

Parameter Type Description
out MutableRect The mutable rectangle receiving UV bounds.

Returns boolean: True if UV resolution succeeded..

AnimatedTexture::setAnimation(int)

Sets the duration of one animation frame in game ticks.

Parameter Type Description
ticksPerFrame int The tick duration per frame.

Returns AnimatedTexture: This animated texture instance for chaining..

AnimatedTexture::setAnimation(int, int)

Sets the inclusive frame index range; playing backwards if from > to.

Parameter Type Description
from int The starting frame index.
to int The ending frame index.

Returns AnimatedTexture: This animated texture instance for chaining..

AnimatedTexture::setCellSize(int)

Configures a square cell size in pixels for grid slicing.

Parameter Type Description
size int The cell size in pixels.

Returns AnimatedTexture: This animated texture instance for chaining..

AnimatedTexture::setCellSize(int, int)

Configures width and height of each animation grid cell in pixels.

Parameter Type Description
width int The cell width in pixels.
height int The cell height in pixels.

Returns AnimatedTexture: This animated texture instance for chaining..

AnimatedTexture::sheet()

Returns the underlying sprite sheet texture handle.

Returns TextureHandle: The underlying sprite sheet texture..

AnimatedTexture::ticksPerFrame()

Returns the number of game ticks each frame remains visible.

Returns int: The ticks per frame duration..

AnimatedTexture::width()

Returns the visual cell width in pixels.

Returns int: The cell width in pixels..