![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
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. | |
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.
| 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.
| spr | The sprite data (w, h, then the rows of runs). |
| x | Left edge on screen. |
| y | Top edge on screen. |
| remap | 16 palette indices to draw each colour as, or nullptr (the default) for the colours as they are. |
| scale | Q8 scale: 256 = 1:1 (the default), 512 = double, 128 = half. 0 or less draws nothing. |
|
inlinestatic |
A span sprite's width.
| spr | The sprite data. |
|
inlinestatic |
A span sprite's height.
| spr | The sprite data. |
| 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().
| spr | The sprite data. |
| ax | Pivot column in the sprite. |
| ay | Pivot row in the sprite. |
| px | Screen column the pivot lands on. |
| py | Screen row the pivot lands on. |
| angle | Rotation, 256 = a full turn, clockwise on screen. |
| scale | Q8 scale, 256 = 1:1 (the default); below 8 counts as 8, 0 or less draws nothing. |
| remap | 16 palette indices to draw each colour as, or nullptr. |