Cauldron2D.Sheet (Cauldron2D v0.1.3)

Copy Markdown View Source

A Cauldron2D.Atlas packed onto one raster, with an index of where every art is.

sheet = Cauldron2D.Sheet.pack(:my_game)
Cauldron2D.Sheet.index(sheet, "/atlas.png")

Every frame of every art is a tile on the sheet, laid out in rows of columns/0; index 0 is left empty for "nothing here", so arts count from 1. arts maps each art name to the index of its first frame, frames gives each index's pixel position on the sheet, and anim maps the first index of each animated art to its indices and rate. index_at/3 is the index showing at a time. An art may be any term the atlas keys it by; in the wire form it is named by inspect/1 unless it is an atom.

Summary

Functions

How many tiles wide a sheet is.

The sheet's pixel size.

What a client needs to draw from the sheet at url: the tile size, the columns, the void colour as #rrggbb, the arts' indices by name, the frames' positions and the animations keyed by their first index as a string.

The index showing at at_ms for an art whose first index is index; index itself when it is not animated.

Lay every frame of every art of atlas out on one raster.

Types

t()

@type t() :: %{
  tile: pos_integer(),
  columns: pos_integer(),
  rows: pos_integer(),
  arts: %{required(Cauldron2D.Atlas.art()) => pos_integer()},
  frames: [[non_neg_integer()]],
  anim: %{
    required(pos_integer()) => %{indices: [pos_integer()], fps: pos_integer()}
  },
  raster: FrenchCurve.Raster.t(),
  void: Cauldron2D.Atlas.rgb()
}

Functions

columns()

@spec columns() :: pos_integer()

How many tiles wide a sheet is.

dimensions(map)

@spec dimensions(t()) :: {pos_integer(), pos_integer()}

The sheet's pixel size.

index(sheet, url)

@spec index(t(), String.t()) :: map()

What a client needs to draw from the sheet at url: the tile size, the columns, the void colour as #rrggbb, the arts' indices by name, the frames' positions and the animations keyed by their first index as a string.

index_at(map, index, at_ms)

@spec index_at(%{anim: map()}, pos_integer(), integer()) :: pos_integer()

The index showing at at_ms for an art whose first index is index; index itself when it is not animated.

pack(atlas)

@spec pack(Cauldron2D.Atlas.t() | Cauldron2D.Atlas.name()) :: t()

Lay every frame of every art of atlas out on one raster.