CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Span sprites

The compact run-length sprite format (sprite4): plain, scaled, recoloured and rotated. More...

Functions

void gfx_sprite4 (const uint8_t *spr, int x, int y, const uint8_t *remap=nullptr, int scale=256)
 Draws a span sprite, optionally recoloured and scaled.
 
static int gfx_sprite4W (const uint8_t *spr)
 A span sprite's width.
 
static int gfx_sprite4H (const uint8_t *spr)
 A span sprite's height.
 
void gfx_sprite4Rot (const uint8_t *spr, int ax, int ay, int px, int py, uint8_t angle, int scale=256, const uint8_t *remap=nullptr)
 Draws a span sprite rotated and scaled about a pivot.
 

Detailed Description

The compact run-length sprite format (sprite4): plain, scaled, recoloured and rotated.

The compact sprite format two CHGame titles arrived at independently. Each row is a list of runs of one colour, so the art is small and a run is a fill, not a pixel loop:

w, h, then per row:  n, then n bytes of  (len - 1) << 4 | colour

Runs are 1..16 px. Colour 15 is transparent (a skip), and trailing transparency is left out. extras/sprite4.py packs a PNG.

Every pixel is drawn through remap[colour] (nullptr = as is), so ONE image serves many looks: a team colour, a red damage flash, a white hit flash, a solid silhouette for an outline. With 16 colours, palette swapping is the natural way to get variety.

#include "slime.h" // python extras/sprite4.py slime.png SLIME > slime.h
gfx_sprite4(SLIME, 40, 60); // as drawn
gfx_sprite4(SLIME, 40, 60, redFlash); // through a 16-entry remap
gfx_sprite4(SLIME, 40, 60, nullptr, 512); // double size
void gfx_sprite4(const uint8_t *spr, int x, int y, const uint8_t *remap=nullptr, int scale=256)
Draws a span sprite, optionally recoloured and scaled.

Function Documentation

◆ gfx_sprite4()

void gfx_sprite4 ( const uint8_t *  spr,
int  x,
int  y,
const uint8_t *  remap = nullptr,
int  scale = 256 
)

Draws a span sprite, optionally recoloured and scaled.

Scaling is nearest neighbour, about the top-left corner. 1:1 has its own fast path, so leave it at 256 unless you mean it.

Parameters
sprThe sprite data (w, h, then the rows of runs).
xLeft edge on screen.
yTop edge on screen.
remap16 palette indices to draw each colour as, or nullptr (the default) for the colours as they are.
scaleQ8 scale: 256 = 1:1 (the default), 512 = double, 128 = half. 0 or less draws nothing.

◆ gfx_sprite4W()

static int gfx_sprite4W ( const uint8_t *  spr)
inlinestatic

A span sprite's width.

Parameters
sprThe sprite data.
Returns
Its width in pixels, at 1:1.

◆ gfx_sprite4H()

static int gfx_sprite4H ( const uint8_t *  spr)
inlinestatic

A span sprite's height.

Parameters
sprThe sprite data.
Returns
Its height in pixels, at 1:1.

◆ gfx_sprite4Rot()

void gfx_sprite4Rot ( const uint8_t *  spr,
int  ax,
int  ay,
int  px,
int  py,
uint8_t  angle,
int  scale = 256,
const uint8_t *  remap = nullptr 
)

Draws a span sprite rotated and scaled about a pivot.

The sprite's pixel (ax, ay) lands on screen at (px, py), turned by angle and scaled by scale. The art is decoded into gfx_chunkScratch(), so it must fit in 1 KB at 4 bpp (32x64, 45x45; a larger sprite draws nothing) and this call waits for any flush in flight first. Per pixel, so costlier than gfx_sprite4().

Parameters
sprThe sprite data.
axPivot column in the sprite.
ayPivot row in the sprite.
pxScreen column the pivot lands on.
pyScreen row the pivot lands on.
angleRotation, 256 = a full turn, clockwise on screen.
scaleQ8 scale, 256 = 1:1 (the default); below 8 counts as 8, 0 or less draws nothing.
remap16 palette indices to draw each colour as, or nullptr.