Header menu logo Mibo

SpriteSheet Module

Functions for creating sprite sheets from various sources.

These are factory functions intended for use at initialization time. Allocations are acceptable here as sheets are typically created once.

Functions and values

Function or value Description

animationNames sheet

Full Usage: animationNames sheet

Parameters:
Returns: string seq

Get the list of animation names in this sheet.

sheet : SpriteSheet
Returns: string seq

fromFrames texture origin animations

Full Usage: fromFrames texture origin animations

Parameters:
    texture : Texture2D - The texture atlas.
    origin : Vector2 - Origin point for drawing (typically center of frame).
    animations : (string * Animation)[] - Array of (name, animation) struct tuples.

Returns: SpriteSheet

Create a sprite sheet from explicit frame rectangles.

This is the most flexible constructor - use this when you've already parsed animation data from any format (TexturePacker, Aseprite, custom).

texture : Texture2D

The texture atlas.

origin : Vector2

Origin point for drawing (typically center of frame).

animations : (string * Animation)[]

Array of (name, animation) struct tuples.

Returns: SpriteSheet

fromGrid texture frameWidth frameHeight columns animations

Full Usage: fromGrid texture frameWidth frameHeight columns animations

Parameters:
    texture : Texture2D - The texture atlas.
    frameWidth : int - Width of each frame in pixels.
    frameHeight : int - Height of each frame in pixels.
    columns : int - Number of columns in the sprite sheet.
    animations : GridAnimationDef[] - Array of GridAnimationDef records.

Returns: SpriteSheet

Create a sprite sheet from a uniform grid layout.

Use this for sprite sheets where all frames are the same size arranged in a grid (common for retro-style games).

texture : Texture2D

The texture atlas.

frameWidth : int

Width of each frame in pixels.

frameHeight : int

Height of each frame in pixels.

columns : int

Number of columns in the sprite sheet.

animations : GridAnimationDef[]

Array of GridAnimationDef records.

Returns: SpriteSheet

single texture frames fps loop

Full Usage: single texture frames fps loop

Parameters:
Returns: SpriteSheet

Create a single-animation sprite sheet.

Convenience function for simple sprites with just one animation (e.g., a spinning coin, flickering torch).

texture : Texture2D
frames : Rectangle[]
fps : float32
loop : bool
Returns: SpriteSheet

static' texture sourceRect

Full Usage: static' texture sourceRect

Parameters:
Returns: SpriteSheet

Create a sprite sheet for a single static frame (no animation).

texture : Texture2D
sourceRect : Rectangle
Returns: SpriteSheet

tryGetAnimationIndex name sheet

Full Usage: tryGetAnimationIndex name sheet

Parameters:
Returns: int voption
Modifiers: inline

Try to get the index for an animation name.

Use this at load time to resolve animation names to indices, then use index-based playback during gameplay for zero allocations.

name : string
sheet : SpriteSheet
Returns: int voption

withNormalMap nm sheet

Full Usage: withNormalMap nm sheet

Parameters:
Returns: SpriteSheet

Add a normal map to an existing sprite sheet.

nm : Texture2D
sheet : SpriteSheet
Returns: SpriteSheet

Type something to start searching.