Cauldron2D.Wx.Sheet (Cauldron2D.Wx v0.1.3)

Copy Markdown View Source

A sprite sheet PNG as wx bitmaps: the sheet scaled up once with nearest-neighbour sampling, and a bitmap per index cut from it on first use.

sheet = Cauldron2D.Wx.Sheet.load(index, png, 2)
bitmap = Cauldron2D.Wx.Sheet.bitmap(sheet, 7)

index is what Cauldron2D.Net.Wire.sheet/1 gives; png the bytes; the scale the pixels a sheet pixel becomes. Needs a running wx. The cut bitmaps are kept in a public ETS table, so any process with the wx environment can draw from the sheet: the sheet's own, or one given as :bitmaps and shared by many sheets, which then lives as long as its owner rather than any one sheet — a painter in another process can hold a sheet the loader has moved on from and still draw it.

Summary

Functions

The indices the sheet animates: the first index of every animated art.

The bitmap for index, cut on first use; nil for an index the sheet has not got.

The bitmap for index as it shows at at_ms, following the sheet's animations.

Load the sheet, scaled scale times — a whole number, or a fraction such as 0.25 that leaves a tile a whole number of pixels. :bitmaps is an ETS table to keep the cut bitmaps in; default a new one of the sheet's own.

The pixel size of a tile on this sheet.

Let the sheet's cut bitmaps go, leaving the table to any other sheet sharing it.

Types

t()

@type t() :: %Cauldron2D.Wx.Sheet{
  anim: map(),
  bitmaps: :ets.table(),
  frames: [{integer(), integer()}],
  id: integer(),
  image: term(),
  scale: number(),
  tile: pos_integer(),
  void: {byte(), byte(), byte()}
}

Functions

animated(sheet)

@spec animated(t()) :: MapSet.t()

The indices the sheet animates: the first index of every animated art.

bitmap(sheet, index)

@spec bitmap(t(), non_neg_integer()) :: term() | nil

The bitmap for index, cut on first use; nil for an index the sheet has not got.

bitmap_at(sheet, index, at_ms)

@spec bitmap_at(t(), non_neg_integer(), integer()) :: term() | nil

The bitmap for index as it shows at at_ms, following the sheet's animations.

load(index, png, scale, opts \\ [])

@spec load(
  %{tile: pos_integer(), frames: [{integer(), integer()}]},
  binary(),
  number(),
  keyword()
) ::
  t()

Load the sheet, scaled scale times — a whole number, or a fraction such as 0.25 that leaves a tile a whole number of pixels. :bitmaps is an ETS table to keep the cut bitmaps in; default a new one of the sheet's own.

pixels(sheet)

@spec pixels(t()) :: pos_integer()

The pixel size of a tile on this sheet.

unload(sheet)

@spec unload(t()) :: :ok

Let the sheet's cut bitmaps go, leaving the table to any other sheet sharing it.