term.gfx.sprite — Lilush API

←index

← term.gfx

Overview

Sprites — blit sources for the canvas.

Everything here is duck-typed for canvas:blit: a sprite is any table that carries a surface (a term.gfx_core userdata) plus a source sub-rect (sx, sy, sw, sh) and its size (w, h). Four kinds:

Functions

NameSignature
spritesprite(source, opts) -> sprite, err
sheetsheet(source, opts) -> sheet, err
artart(spec) -> sprite
animanim(spec) -> anim

sprite(source, opts) -> sprite, err

Create a sprite viewing a region of a canvas/surface/sprite

opts:

The returned sprite shares the source pixels — it is a lightweight view, not a copy.

sheet(source, opts) -> sheet, err

Create a sprite sheet (atlas) over a source image

Two ways to define frames:

sheet:frame(index_or_name) returns a sprite; sheet:nframes() the count.

art(spec) -> sprite

Create a pseudo-pixel-art sprite from a char-map and palette

spec:

The art is rasterized once into its own surface and returned as a sprite, so it blits/flips/tints/atlases like any other. A monochrome mask (one palette entry of white) can be recoloured at blit time via the tint option.

anim(spec) -> anim

Create an animated sprite from a frame sequence

spec:

The anim is itself a blit source delegating to the current frame: call :update(dt) each tick, then canvas:blit(anim, x, y) (or anim:current()).