flix

0.81.0

Sprite

enum SpriteSource
case Sprite({ height = Int32, rows = Vector[String], runs = List[(Int32, Int32, Int32)], width = Int32 })

Pixel art, as data.

A sprite is written out as rows of text -- # for a lit pixel, anything else for empty -- so the artwork is legible in the source and can be edited without a drawing tool. There are no image files anywhere in this project.

Each row is collapsed into horizontal runs of lit pixels, and drawing emits one rectangle per run rather than one per pixel -- roughly a quarter of the draw calls. The runs are computed once, by Sprite.of, and stored: parsing the text on every frame for every invader was enough to halve the frame rate.

Definitions

def draw(sprite: Sprite, centre: Vec2, scale: Float32): Unit \ Canvas§ Source

Draws a sprite centred on centre, with each sprite pixel scale screen pixels wide.

def drawScaled(sprite: Sprite, centre: Vec2, scaleX: { scaleX = Float32 }, scaleY: { scaleY = Float32 }): Unit \ Canvas§ Source

Draws a sprite centred on centre, stretched independently in each axis.

Separate axes so a shape can be made wide without also becoming tall -- which is what a flying saucer wants and a square pixel does not give you.

The two scales are named: they are both Float32, and swapping them silently transposes the sprite.

def height(sprite: Sprite): Int32§ Source

The sprite's height in cells.

def litPixels(sprite: Sprite): Int32§ Source

The number of lit pixels. Handy for tests; not used when drawing.

def of(rows: Vector[String]): Sprite§ Source

Builds a sprite from rows of text. The width is the longest row.

def rows(sprite: Sprite): Vector[String]§ Source

The rows of text the sprite was built from.

def runs(sprite: Sprite): List[(Int32, Int32, Int32)]§ Source

Every lit run in the sprite, as (row, startColumn, length), top row first.

def width(sprite: Sprite): Int32§ Source

The sprite's width in cells -- the longest row.