Sprite

:= {
    texture : Texture,
    source : Rect,
    pos : Vec2,
    origin : Vec2,
    rotation : F32,
    scale : Vec2,
    tint : Color,
}

Sprite module - pure helpers for texture sprites and simple animations.

Drawing still goes through Draw/Assets. This module provides a compact game-facing shape for sprites, spritesheet frame rectangles, and animation state.

source : Sprite, Rect -> Sprite

Return a copy using a new texture source rectangle.

pos : Sprite, Vec2 -> Sprite

Return a copy at a new destination position.

origin : Sprite, Vec2 -> Sprite

Return a copy with a new rotation and scaling origin.

centered : Sprite -> Sprite

Return a copy whose origin is centered in the scaled sprite.

rotation : Sprite, F32 -> Sprite

Return a copy with rotation in degrees.

scale_xy : Sprite, Vec2 -> Sprite

Return a copy with independent horizontal and vertical scale.

scale : Sprite, F32 -> Sprite

Return a copy with uniform scale.

tint : Sprite, Color -> Sprite

Return a copy with a multiplicative tint.

draw! : Sprite, Frame => {  }

Draw the sprite using its current transform and tint.

from_texture : Texture -> Sprite

Create a sprite covering the complete texture with identity transform.

with_source : Sprite, Rect -> Sprite

Compatibility function for the source receiver method.

with_pos : Sprite, Vec2 -> Sprite

Compatibility function for the pos receiver method.

with_origin : Sprite, Vec2 -> Sprite

Compatibility function for the origin receiver method.

with_origin_center : Sprite -> Sprite

Compatibility function for the centered receiver method.

with_rotation : Sprite, F32 -> Sprite

Compatibility function for the rotation receiver method.

with_scale_xy : Sprite, Vec2 -> Sprite

Compatibility function for the scale_xy receiver method.

with_scale : Sprite, F32 -> Sprite

Compatibility function for the scale receiver method.

with_tint : Sprite, Color -> Sprite

Compatibility function for the tint receiver method.

sheet_frame : { frame_size : Vec2, row : U64, col : U64 } -> Rect

Return a source rectangle for a regular grid spritesheet.

animation : { frame_count : U64, fps : F32 } -> Animation

Create animation state at its first frame.

step : Animation, F32 -> Animation

Advance animation state by elapsed seconds without allocating.

animation_source : Animation, { frame_size : Vec2, row : U64 } -> Rect

Return the current frame's source rectangle for a spritesheet row.

Animation : {
    frame : U64,
    frame_count : U64,
    fps : F32,
    elapsed : F32,
}

Frame index and elapsed-time state for a regular spritesheet animation.