Gridwright Start for $1

How to Palette Swap Sprites: Online and in Godot 4

Recolor a sprite or a whole sheet for a new team, enemy or night scene: palette swap online with locked skin colours, then swap colours live in Godot 4.

Palette Swapper at work
Palette Swapper at work: New colours for any sprite or sheet.

Your goblin is done. Four directions, eight frames each, a nice green tunic. Now the game needs a red goblin for the second camp, a pale one for the elite version and a blue one for the night level. So you open the sheet in your paint program and start filling. Thirty-two frames, six colours per goblin, three goblins. Somewhere in frame 27 one pixel of the old green survives, and you only see it when the goblin turns left in the finished game.

Then the artist changes the goblin's ears, and you do all of it again.

A palette swap fixes this. You change the colours once, as a list, and every frame follows. This guide shows the two ways games do it: bake the new colours into new PNGs, or swap them live in Godot 4 with a small shader. The Palette Swapper does the first in your browser and writes the colour map that the second one reads.

What a palette swap is

Pixel art uses a small, exact set of colours. A goblin might have twelve: an outline, three greens for the tunic, three skin tones, two browns for the belt, the eyes. Every pixel of the darkest green has exactly the same value, so you can replace that value everywhere at once with no selections and no masks.

Top-Down Characters
Top-Down Characters: 16x16 top-down pixel art RPG characters: 4 directions, idle and walk animations, emotes. One of the 150 packs in Gridwright.

A palette swap is that replacement, colour for colour. The outline, the shading steps and the transparent pixels stay where they were, so every frame of the sheet still lines up and the animation plays as before. Old 8-bit and 16-bit games made player two, the stronger enemy and the poisoned version of a hero this way, from one drawing.

Plan the swap before you touch a colour

Most bad recolours come from changing the wrong colours, or the right ones in the wrong order.

Side-View Characters
Side-View Characters: 10 animated 32x32 pixel art heroes and enemies: run, jump, attack, hurt and death, left and right. One of the 150 packs in Gridwright.
  1. Find the ramp that carries the team colour. In the goblin it is the tunic's three greens, dark to light. Those change.
  2. Decide what stays. Skin, eyes, teeth, metal and usually the outline stay as they are. A red team with red skin reads as a different creature.
  3. Keep dark dark. The new ramp needs the same order as the old one: the darkest green becomes the darkest red, the highlight becomes the highlight. Swap them out of order and the shading turns inside out.
  4. Match the number of steps. Three greens want three reds. With two reds, two of the greens fall onto the same red and the folds of the tunic go flat.

For a quick elite or ghost version, you often need no palette at all: turn the hue of the whole sprite, or pull its saturation down and its lightness up.

Way 1: bake new sprites

Baking means you save each recolour as its own PNG. It is the simplest route for any engine: the red goblin is just another texture. Here is how it goes in the Palette Swapper:

Pixel Palette & Shading Ramp Maker: Shading ramps and palettes for pixel art
Pixel Palette & Shading Ramp Maker: Shading ramps and palettes for pixel art. Included in Gridwright.
  1. Drop in the sprite or the whole sheet (PNG, GIF or WebP). The tool lists every colour in it, darkest first, and shows the original and the recolour side by side. Hover a swatch to see how many pixels use it.
  2. Lock the colours that stay. Click the lock on the skin tones and the eyes. Locked colours keep their value whatever you do next.
  3. Fit a palette. Load a .hex, .gpl or .pal file from your art program, or pick one of the ready palettes: Team red, Team blue, Team green, Team gold, Moonlight, Ember, Sepia and Green LCD. Then choose how it fits. Keep the shading lays the sprite's dark-to-light order over the palette's dark-to-light order: the one for team colours and enemy variants. Closest colour gives each colour the palette colour that looks nearest to it: the one for bringing a sprite into a game's fixed palette, such as a strict four-colour handheld look.
  4. Fine-tune. The hue slider turns every unlocked colour by up to 180 degrees either way, saturation moves up to 100% and lightness up to 50%. Any single colour can be set by hand with its colour picker, and a colour you set by hand wins over the sliders.
  5. Keep it and make the next one. Press Keep this one and make another, pick the next palette, and so on for every team.
  6. Download. One zip holds the original, every recolour as a PNG of the same size, a .hex and a .gpl palette for each recolour (Aseprite, GIMP and most pixel editors open them), and a JSON map of which colour became which. If you only want the one sprite, there is a single PNG download too.

Transparency is never touched, half-transparent edge pixels included, so the frames of a recoloured sheet line up exactly with the original's. The tool lists up to 256 colours, the most used ones. Pixel art stays far under that. A photo has thousands, and the ones past 256 are left as they are.

Need a new ramp first? The Pixel Palette & Shading Ramp Maker builds one with the number of steps you choose, and the Color Palette Extractor takes the palette of any picture, such as a mood board for your night level.

Your game, looking finished

Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.

Start: 3 days for $1 See everything it includes

Way 2: swap colours live in Godot 4

Baking gives you one PNG per variant. If your players pick their own colours, or you have eight teams and a 40-frame sheet, that is a lot of copies. A shader can swap the colours while the game runs instead: one sheet, any number of variants.

Create a new shader in Godot (palette_swap.gdshader):

shader_type canvas_item;

const int MAX_COLORS = 32;
uniform int color_count = 0;
uniform vec4 from_colors[MAX_COLORS] : source_color;
uniform vec4 to_colors[MAX_COLORS] : source_color;

void fragment() {
	vec4 c = texture(TEXTURE, UV);
	for (int i = 0; i < color_count; i++) {
		if (distance(c.rgb, from_colors[i].rgb) < 0.002) {
			c.rgb = to_colors[i].rgb;
			break;
		}
	}
	COLOR = c;
}

Each pixel looks for its colour in the from_colors list and takes the matching colour from to_colors. The 0.002 limit is smaller than one step of an 8-bit colour (1/255), so only the exact colour matches. Alpha is kept as it is.

Typing 32 colours into the inspector by hand is no fun, so let the colour map from the Palette Swapper's zip fill the lists. Add a ShaderMaterial with this shader to your Sprite2D, put the zip's JSON file in your project, and attach this script:

extends Sprite2D

@export_file("*.json") var colour_map := "res://goblin_colours.json"
@export var variant := "team_red"

func _ready() -> void:
	material = material.duplicate()  # each sprite keeps its own colours
	var data = JSON.parse_string(FileAccess.get_file_as_string(colour_map))
	for v in data["variants"]:
		if v["name"] != variant:
			continue
		var from := PackedColorArray()
		var to := PackedColorArray()
		for old in v["colours"]:
			if old != v["colours"][old]:
				from.append(Color(old))
				to.append(Color(v["colours"][old]))
		material.set_shader_parameter("from_colors", from)
		material.set_shader_parameter("to_colors", to)
		material.set_shader_parameter("color_count", from.size())

Set variant to the name of the recolour, as the JSON lists it: the palette's name in lower case when you fitted one (Team red becomes team_red), otherwise variant_1, variant_2 and so on, or recoloured if you downloaded without pressing Keep. The script skips the colours that didn't change, such as the locked skin. material.duplicate() matters: without it, every goblin that shares the material shows the colours of the last one that loaded. On an AnimatedSprite2D, change the first line to extends AnimatedSprite2D and every frame of every animation takes the new colours.

We rendered this shader and script in Godot 4.7.2 and compared every pixel with the expected colours: swapped colours, locked colours, a half-transparent edge and a clear pixel all came out right.

Two Godot settings keep it exact:

  • Import the texture as Lossless. That is Godot's default for 2D. VRAM compression changes colours slightly, and then nothing matches.
  • Use Nearest filtering (Project Settings › Rendering › Textures › Canvas Textures › Default Texture Filter, or the sprite's own Texture › Filter). Linear filtering blends neighbouring pixels into colours that aren't in the list.

If a sprite has more than 32 colours that change, raise MAX_COLORS.

When a swap goes wrong

  • A few pixels keep the old colour. Two colours that look the same differ by one value, for example #3a6b2e and #3a6b2f. Both are in the tool's list: change both, or fit with Closest colour, which gives them the same new colour.
  • The shading went flat. The new palette has fewer steps than the ramp it replaces, so Keep the shading put two old colours on one new one. Use a ramp with as many steps.
  • The skin changed too. Lock it before you fit the palette or move the sliders.
  • Godot shows the old colours. Check that variant matches a name in the JSON, that the texture import is Lossless, and that color_count isn't 0 in the remote inspector.

Make the next team in a minute

Open the Palette Swapper and drop in your sprite or sheet: the colour list and the before-and-after view are there in seconds. It is one of 44 tools in Gridwright, with 150 asset packs whose characters and creatures are ready to recolour. Start for 3 days for $1, then $17 a month, and give your second team its colours today.

Your game, looking finished

Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.

Start: 3 days for $1 See everything it includes