Sprites
drawSprite
Draw a sprite at a world position. Sprite 1 is the first sprite. Pass a width and height in tiles to draw a larger block, and flipX or flipY to mirror it.
- drawSprite(spriteIndex, x, y) -> void
- drawSprite(spriteIndex, x, y, w, h [, flipX [, flipY]]) -> void
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
- x — World-space X in pixels.
- y — World-space Y in pixels.
- w — Width in tiles: how many tiles to draw across.
- h — Height in tiles: how many tiles to draw downward.
- [flipX] — Optional: mirror horizontally when true.
- [flipY] — Optional: mirror vertically when true.
Returns
- void — No return value.
Examples
-- Draw sprite 1 at (40, 60).
drawSprite(1, 40, 60)
-- Draw a 2 by 2 block of sprites, flipped left to right.
drawSprite(1, 40, 60, 2, 2, true)drawSpriteRotated
Draw a sprite block rotated around its top-left corner.
- drawSpriteRotated(spriteIndex, x, y [, w, h, flipX, flipY, angleDeg]) -> void
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
- x — World-space X in pixels.
- y — World-space Y in pixels.
- [w] — Optional width in tiles (default 1).
- [h] — Optional height in tiles (default 1).
- [flipX] — Optional: mirror horizontally when true.
- [flipY] — Optional: mirror vertically when true.
- [angleDeg] — Optional rotation in degrees.
Returns
- void — No return value.
Examples
-- Draw sprite 1 at (40, 60), turned 90 degrees.
drawSpriteRotated(1, 40, 60, 1, 1, false, false, 90)drawSubSprite
Draw a sub-rectangle of the concatenated spritesheet with optional scaling and flipping. Y continues past 128 for extra sheets.
- drawSubSprite(sx, sy, sw, sh, dx, dy [, dw, dh, flipX, flipY]) -> void
Parameters
- sx — Left edge of the region on the sprite sheet (pixels).
- sy — Top edge of the region on the concatenated sprite sheet (pixels). Y continues past 128 for extra sheets.
- sw — Width of the region on the sprite sheet (pixels).
- sh — Height of the region on the sprite sheet (pixels).
- dx — Where to draw on screen, X in world pixels.
- dy — Where to draw on screen, Y in world pixels.
- [dw] — Optional draw width in pixels; omit to match source width.
- [dh] — Optional draw height in pixels; omit to match source height.
- [flipX] — Optional: mirror horizontally when true.
- [flipY] — Optional: mirror vertically when true.
Returns
- void — No return value.
Examples
-- Copy an 8 by 8 patch from the top-left of the sprite sheet to (40, 60).
drawSubSprite(0, 0, 8, 8, 40, 60)spriteSheetGetPixel
Read a palette color index from the concatenated sprite sheet at sheet coordinates. Y continues past 128 for extra sheets.
- spriteSheetGetPixel(x, y) -> int
Parameters
- x — Position on the sprite sheet, X in pixels.
- y — Position on the concatenated sprite sheet, Y in pixels. Y continues past 128 for extra sheets.
Returns
- int
Examples
-- Read the colour of sprite-sheet pixel (4, 4).
local color = spriteSheetGetPixel(4, 4)spriteSheetSetPixel
Write a palette color index into the concatenated sprite sheet at sheet coordinates. Y continues past 128 for extra sheets.
- spriteSheetSetPixel(x, y, color) -> void
Parameters
- x — Position on the sprite sheet, X in pixels.
- y — Position on the concatenated sprite sheet, Y in pixels. Y continues past 128 for extra sheets.
- color — Palette color to write.
Returns
- void — No return value.
Examples
-- Paint sprite-sheet pixel (4, 4) with colour 7.
spriteSheetSetPixel(4, 4, 7)spriteGetFlags
Return the full 8-bit flag byte for a sprite.
- spriteGetFlags(spriteIndex) -> int
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
Returns
- int
Examples
-- Read all 8 flag bits for sprite 1.
local flags = spriteGetFlags(1)spriteSetFlags
Set the entire 8-bit flag byte for a sprite.
- spriteSetFlags(spriteIndex, flags) -> void
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
- flags — 8-bit sprite flags.
Returns
- void — No return value.
Examples
-- Set sprite 1's flags to bit pattern 3.
spriteSetFlags(1, 3)spriteGetFlag
Read a single flag bit for a sprite (0–7).
- spriteGetFlag(spriteIndex, bit) -> bool
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
- bit — Which flag bit (0–7).
Returns
- bool
Examples
-- True when flag bit 0 is set on sprite 1.
local solid = spriteGetFlag(1, 0)spriteSetFlag
Set or clear a sprite flag bit; value defaults to true.
- spriteSetFlag(spriteIndex, bit [, value]) -> void
Parameters
- spriteIndex — Sprite index (1-based). Sheet 0 is 1–256, sheet 1 is 257–512, and so on.
- bit — Which flag bit (0–7).
- [value] — Optional; true or false (defaults to true).
Returns
- void — No return value.
Examples
-- Turn on flag bit 0 for sprite 1.
spriteSetFlag(1, 0)
-- Turn off flag bit 0 for sprite 1.
spriteSetFlag(1, 0, false)