Skip to content

spritebatch

spritebatch

Sprite batches: many copies of one texture built up together and drawn in one go. Add sprites with add, draw the whole thing with draw, and clear to start over. The current color set with setColor tints sprites added after it.

SpriteBatch

type SpriteBatch = ref object

Many copies of one texture, built up with add and drawn in one call.

Fields

  • texture Texture
  • color Color

newSpriteBatch

proc newSpriteBatch(image: Texture): SpriteBatch

A sprite batch drawing copies of image.

Parameters

  • image (Texture)

Returns

SpriteBatch

setColor

proc setColor(batch: SpriteBatch; r, g, b: uint8; a: uint8 = 255)

Tint the sprites added after this call.

Parameters

  • batch (SpriteBatch)
  • r (uint8)
  • g (uint8)
  • b (uint8)
  • a (uint8)

clear

proc clear(batch: SpriteBatch)

Empty the batch to build it up again.

Parameters

  • batch (SpriteBatch)

count

proc count(batch: SpriteBatch): int

How many sprites the batch holds.

Parameters

  • batch (SpriteBatch)

Returns

int

add

proc add(batch: SpriteBatch; x, y: float; angle = 0.0; sx = 1.0; sy = 1.0; ox = 0.0; oy = 0.0)

Add one copy of the texture at (x, y), with the same rotation, scale and

origin arguments as drawing an image.

Parameters

  • batch (SpriteBatch)
  • x (float)
  • y (float)
  • angle (auto)
  • sx (auto)
  • sy (auto)
  • ox (auto)
  • oy (auto)

add

proc add(batch: SpriteBatch; quad: Quad; x, y: float; angle = 0.0; sx = 1.0; sy = 1.0; ox = 0.0; oy = 0.0)

Add one copy of just the quad region of the texture, for sprite sheets.

Parameters

  • batch (SpriteBatch)
  • quad (Quad)
  • x (float)
  • y (float)
  • angle (auto)
  • sx (auto)
  • sy (auto)
  • ox (auto)
  • oy (auto)

draw

proc draw(batch: SpriteBatch; nim2d: Nim2d; x = 0.0; y = 0.0)

Draw the whole batch in one call, optionally offset by (x, y), through the

current transform.

Parameters

  • batch (SpriteBatch)
  • nim2d (Nim2d)
  • x (auto)
  • y (auto)
Generated with mkdocstrings-nim