CauldronGPU.Sprite (CauldronGPU v0.3.3)

Copy Markdown View Source

A rectangle of a texture placed in a CauldronGPU.SpriteLayer.

  • texture — the handle of a texture or canvas
  • source — {x, y, width, height} in the texture's pixels, the part drawn; nil (the default) draws the whole texture
  • position — {x, y} in the layer's view, where the sprite's origin lands
  • origin — {x, y} in the source's pixels, the point placed at position and turned about; default {0, 0}
  • scale — {x, y}; negative mirrors, zero draws nothing; default {1, 1}
  • angle — degrees, counter-clockwise as seen; exact at whole quarter turns
  • colour — {r, g, b} from 0 to 1, multiplied into the texture's colours
  • alpha — 0 to 1, multiplied into the texture's alpha
  • mode — :over (the default), :add or :subtract

Colours are display values: they are blended as stored, with no conversion to linear light. A pixel is drawn when its centre lies inside the turned and scaled rectangle; it takes the texture's sample at that point, by the texture's own filter.

:over lays the colour over what is there by its alpha. :add adds the colour times its alpha, each channel at most 1, and adds the alpha. :subtract multiplies each channel by one less the colour times its alpha, keeping the alpha.

Summary

Types

t()

@type t() :: %CauldronGPU.Sprite{
  alpha: number(),
  angle: number(),
  colour: {number(), number(), number()},
  mode: :over | :add | :subtract,
  origin: {number(), number()},
  position: {number(), number()},
  scale: {number(), number()},
  source: {number(), number(), number(), number()} | nil,
  texture: CauldronGPU.Handle.t()
}