0:01 / 0:30
Playback speed

Palette swap

Pick a patch of the character’s coat. Follow its colour through all four palettes.

#SpritesAndImagesSNES era#Sprite

Reusing one sprite with a different set of colours.

The drawing stays the same; only the colour table changes. It’s how old games made a red enemy tougher than the blue one without drawing anything new, and it’s still the cheapest way to make variants and team colours.

Code

src/demos/palette_swap.goose
namespace palette_swap_lesson;
import stage;
import std;
import math;

fn palette(index: i64) -> const u8[:] {
    match index { 0 => "base", 1 => "moss", 2 => "sky", _ => "rose" }
}

export "palette-swap" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("draft");
    let selected = (time / 0.9) as i64 % 4;
    ground(62);
    actor(80, 62, walk(time), 4, palette(selected));
    for i in 4 {
        let x = 26 + i * 30;
        for j in 4 {
            swatch(palette(i), j, x + j * 6, 76);
        }
        box(x - 1, 75, 26, 10, if i == selected { MAG } else { LINE });
    }
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.