Pixel art lava with color cycling
A flat orange lava tile is one of the easiest things to fix in a pixel art game. Paint the lava with palette indices and rotate the colors (color cycling), then add crust, light on the rock, a splash and embers. How each layer works, with a tested Godot shader.
Paste it into Claude Code, Codex, Grok Build or any coding agent.
Copied. Want one of these every week?
The week's game techniques in one free email on Sunday, each with a prompt like this one.
# Add color cycled lava to my game
The lava in my 2D pixel art game is a flat tile that doesn't move. Make it flow with color cycling: the lava pixels keep their place and their colors rotate through short rings, one whole step at a time. Then add crust, light on the rock, a splash where a lava fall lands and embers.
Before you write code, look at my project: engine and language, pixel resolution and camera, how the lava is drawn now (a tilemap, one image, a fall and a pool), which rock stands in front of it, and how the game handles shaders. Keep my lava's shapes and colors where they work. Ask me before changing the art or adding a new rendering system.
## How it works
- Draw the flat look first: the fall as vertical stripes 2 to 4 px wide (dark red edges, orange middle, light orange core), the pool as flat bands by depth whose borders are sine waves rolling away from the fall on the same step clock.
- On top, a sprite whose texture is an index map: red = where in its ring the pixel starts, green = ramp row (a color pattern), blue = ring length, alpha = 255 if it cycles. Clear pixels show the flat look.
- A ring has a few colored entries and the rest clear, so a streak or dash passes and the body color shows again.
- The shader shows entry (start - step) mod ring, step = floor(time * 12). Whole steps only.
- Bake from masks: fall columns for streaks, some pool rows for dashes. The start moves one entry every 3 px along the flow (down the fall, away from the fall's center column `fall_x`). So the last entry of a ring leads: a streak's bright head is at its bottom, a dash's darker pixel at its front.
- Then the layers: crust, light on the rock, a foam crown where the fall lands, embers.
## Numbers that matter
Tested on a 480 x 270 side view scene, lava fall 64 px wide. Keep sizes in art pixels.
- Clock: 12 steps a second; every streak and dash moves 3 px a step.
- Fall: about 45% of the columns get a streak, each column with its own ring (12 to 18 entries) and start. Streaks are 2 to 4 entries (6 to 12 px), 1 px wide.
- Pool: dashes on the rows 4, 7, 12, 17, 24, 31 and 38 px below the surface, each row with its own ring (13 to 19), a dash of 2 to 4 bright entries plus 1 darker, and different starts left and right of the fall.
- Ramp texture: 32 x 16 px. Rows hold color patterns only; ring lengths live in the index map, so rows can be shared.
- Colors: #1e0c16 outline, #3e1a20 #622826 crust, #b0281c #de481e reds, #f67422 #fc922c #ffb238 oranges, #ffde60 #fff0a0 yellows, #fffadc white hot.
- Streak tail / head: edge #f67422 / #fc922c, middle #fc922c / #ffb238, core #ffde60 / #fffadc. Dash bright / darker: rows 4, 7 #ffde60 / #ffb238; rows 12, 17 #ffb238 / #f67422; rows 24, 31 #f67422 / #de481e; row 38 #de481e / #b0281c.
- Bands and crest: formulas in the pseudo code.
- Crust: a dark skin about 2 px wide along the banks, 5 hand-placed pieces on the surface away from the fall, each with a 1 px outline, lighter top, one red crack, bobbing 1 px.
- Light on rock: blur the lava shape, cut into 3 bands, move each rock pixel toward a red-brown version of its own shade by 85%, 60%, 35%. Skip lava and anything that glows itself.
- Splash: the fall flares out over its last 14 px into a foam crown 83 px wide, at most 11 px above the surface, lower half under it. A white line on the surface beside it, a ripple every 1.25 s, 40 droplets per 7.5 s.
- Embers: 34 per 7.5 s, 2 x 2 px yellow while young, then 1 px fading through orange to red.
## Pseudo code
```
# flat look, per step k; d = depth below surface, dx = abs(x - fall_x), wave(c) = 2 pi c k / 90
crest = clamp(round(1.4 + 1.6 sin(0.24 dx - wave(15))), 0, 3) # px above the surface
w2 = round(1.5 sin(0.11 dx - wave(6) + 1))
band = #ffb238 if d < 4 + round(sin(0.16 dx - wave(9)))
#fc922c if d < 10 + w2, #f67422 if d < 18 + w2
#de481e if d < 29 + round(2 sin(0.08 dx - wave(3) + 2)), else #b0281c
# bake, once
ramp_row(colors) = 32 RGBA, colors first, the rest clear
fall_ring(tail, head, dash) = ramp_row([tail] * (dash - 1) + [head])
pool_ring(hi, lo, dash) = ramp_row([hi] * dash + [lo])
for each fall column x with a streak:
ring[x] = random 12..18; dash[x] = random 2..4; phase[x] = random
for each fall pixel y: index[y, x] = ((y // 3 + phase[x]) mod ring[x], row of (stripe, dash), ring[x], 255)
for each dash row r:
ring = random 13..19; dash = random 2..4; phase_left, phase_right = random
for each pool pixel x on row surface + r:
phase = phase_left if x < fall_x else phase_right
index[y, x] = ((dx // 3 + phase) mod ring, row of r, ring, 255)
# shader, per index pixel
if alpha == 0: discard
start, row, ring = round(r * 255), round(g * 255), round(b * 255)
step = floor(time * 12)
i = (start + ring - step mod ring) mod ring # integers, all operands positive
color = ramp texel (i, row) # exact texel, no filtering
```
Godot: `canvas_item` shader, `texelFetch(ramps, ivec2(i, row), 0)`. Unity: sprite shader, point sampling, integer math. With an indexed palette: rotate palette ranges instead.
## Pitfalls
- A filtered, compressed or sRGB-converted index map breaks the rings. Import lossless, nearest, no mipmaps; in Godot also turn off `process/fix_alpha_border` and keep HDR 2D off.
- A float `mod` can return the ring length itself (`mod(-42.0, 14.0)` gave 14), and an integer `%` of a negative number is undefined in GLSL. Use the form above.
- One shared ring and start for all columns makes bands that scroll like a texture.
- Streaks wider than the pool's detail make the fall look like bigger pixels.
- Blending between entries looks like a video filter.
- Rock in front of the pool: cut the lava at the rock and let a stream run on underneath, with a dark line under the rock.
## Check that it works
- A pixel with ring length L looks the same at step s and s + L. For a seamless video loop, use ring lengths that divide the loop.
- Between two steps every streak moves exactly 3 px down and every dash 3 px away from the fall.
- No lava color appears that isn't in the bands or the ramp texture.
- Render the shader at a few steps and compare with a CPU version: every pixel equal. Godot needs a window for this (`--write-movie`).
- With the cycling sprite hidden, the flat look is unchanged.
## Art it needs
The cycling needs masks of the lava and your lava colors. If the lava is painted into a scene, you need a background without it:
- Paint the lava out by hand, or
- If the SpriteCook MCP tools are available in this session, edit the scene with "remove all the lava and its glow, keep everything else exactly the same" for a clean plate, and use the difference as the lava mask. Generate scenes at the model's native grid (480 x 268 for 16:9) or re-sample the raw output on its grid, then snap the plate to a small palette so the rock stays crisp.
Source: SpriteCook (2D game assets made by your coding agent, for Claude, ChatGPT and Cursor)
Full guide with pictures, the clip and tested Godot code: https://www.spritecook.ai/blog/pixel-art-lava-color-cyclingMost lava in 2D games is one orange tile, maybe scrolling. It sits there like paint. Old games had lava that flowed without a single extra frame of art: the pixels stay put and their colors rotate. That's color cycling, and it's still the cheapest way to make lava, water or fire move in pixel art. On top of it I added four small layers: crust, light on the rock, a splash where the fall lands, and embers.
Same cave on both sides. Left is a basic lava tile, right is the same lava with color cycling and four layers on top. The cave, crystals and mushrooms are made with SpriteCook.
Color cycling
In a color cycling picture, a lava pixel doesn't store a color. It stores a place in a short ring of colors. Every step, the whole ring turns by one, so each pixel shows the next color in its ring. Paint the places in order along the flow and the colors travel along it. Artists did this in Deluxe Paint in the 80s, and Mark Ferrari built whole animated landscapes with it.
Mine steps 12 times a second, always a whole step, never in between. That gives it the snappy look of old games.
Two textures
The lava is a sprite whose texture is an index map. Each pixel's red channel says where in its ring it starts, green says which ring, blue says how long the ring is, and alpha says if the pixel cycles at all. Pixels that don't cycle are clear, so the flat lava bands painted underneath show through.
The rings live in a second texture, one ring per row. Mine is 32 by 16 pixels. Most of each ring is clear, so a streak is a few bright entries followed by nothing, and the body color shows the rest of the time.
Streaks down the fall
- The fall is flat stripes, 2 to 4 px wide: dark red at the edges, orange in the middle, light orange in the core.
- About 45% of the columns get a streak. Each of those columns has its own ring of 12 to 18 entries and its own starting point, so no two streaks line up.
- Going down a column, the place in the ring moves one entry every 3 px. A streak is 2 to 4 entries long, so 6 to 12 px, with its brightest pixel at the bottom.
- One step moves everything 3 px down. At 12 steps a second that's 36 px a second.
My first try had wide streaks that jumped 4 px a step. Next to the pool's 1 px detail they looked like they were drawn at a bigger pixel size. Keep the streaks 1 px wide so the fall and the pool match.
Dashes across the pool
- The pool is flat bands by depth: light orange at the top, then two oranges, then two reds. Their borders are sine waves that roll away from the fall.
- Seven rows, at 4, 7, 12, 17, 24, 31 and 38 px below the surface, get dashes. Along a row, the place in the ring moves one entry every 3 px away from the fall, so the dashes flow outward at the same 3 px a step as the fall.
- Each row has its own ring of 13 to 19 entries and a dash of 2 to 4, plus one darker pixel behind it. The left and right side start out of step, so the pool doesn't look mirrored around the fall.
- The surface is a scalloped crest up to 3 px high that also rolls outward.
Where a rock stands in front of the pool, cut the lava at the rock and let a stream run on underneath it, with a dark line under the rock. If the lava just runs across, it reads as a picture pasted over the cave.
Crust where it cools
Lava cools where it slows down: along the banks and away from the fall. A dark skin about 2 px wide follows the banks, and 5 hand placed pieces float on the surface (lumps, a flat slab, a broken shard and one sunk below the surface). Each has a 1 px outline, a lighter top and one red crack, and bobs by 1 px.
Light on the rock, in hard bands
Blur the lava's shape, then cut the blur into 3 bands. In each band, every rock pixel moves toward a red brown version of its own shade, by 85%, 60% and 35%. A smooth glow would look painted on. Hard bands look like pixel art. The lava itself and anything that glows on its own (my crystals) stay out of it.
Where the fall lands
This is where a basic lava fall looks the worst, a stripe that just stops at a line. Mine flares out over the last 14 px and pours into a wide, low foam crown, 83 px across and at most 11 px above the surface, with its lower half under the surface line. Lumps roll outward over it. Around it, a white line on the surface, a ripple every 1.25 s, and 40 chunky droplets a loop thrown from its sides.
My first try was a row of round foam balls. It looked like a row of coins. Keep the crown low and wide.
Embers
34 embers a loop rise off the pool. They're 2 by 2 px and yellow while young, then 1 px and fading through orange to red.
The code
The core is a short shader and a bake that writes the two textures:
lava_cycle.gdshadergoes on the Sprite2D that shows the index map. Draw it over your lava art (the flat bands), and give it the ramp texture.- The bake (Python here, any language works) writes the index map and the ramp texture from your lava's masks: which pixels are fall, which rows of the pool get dashes, and the rings.
lava_cycle.gdshader:
// Color cycling for a Sprite2D whose texture is an index map instead of colors.
// Each index pixel stores: r = where in its ring it starts, g = which row of the ramp texture,
// b = how long its ring is, a = 255 if the pixel cycles at all.
// Every step, every cycling pixel moves one entry back through its ring, so the colors flow.
shader_type canvas_item;
uniform sampler2D ramps : filter_nearest; // one ring of colors per row, clear = art shows
uniform float steps_per_second = 12.0; // the cycling clock: whole steps, never in between
uniform int step_override = -1; // 0 or more freezes that step (tests, pausing)
void fragment() {
vec4 cell = texture(TEXTURE, UV);
if (cell.a < 0.5) {
discard; // not lava: the art underneath shows
}
int start = int(round(cell.r * 255.0));
int row = int(round(cell.g * 255.0));
int ring = int(round(cell.b * 255.0));
int step = step_override >= 0 ? step_override : int(floor(TIME * steps_per_second));
int i = (start + ring - step % ring) % ring; // ints, all positive: % of a negative is undefined
COLOR = texelFetch(ramps, ivec2(i, row), 0);
}
The bake, the parts that decide the rings:
def ramp_row(colors_by_index, length=RAMP_W):
"""One ring of a ramp texture: colors for the first entries, the rest clear (the art shows)."""
row = np.zeros((length, 4), np.uint8)
for i, c in enumerate(colors_by_index):
row[i] = c
return row
def fall_ring(tail, head, dash):
return ramp_row([tail] * (dash - 1) + [head]) # a streak: dim tail, bright bottom pixel
def pool_ring(hi, lo, dash):
return ramp_row([hi] * dash + [lo]) # a dash: bright run, one darker pixel last
def bake_cell(index, y, x, start, row, ring):
"""r: where in its ring it starts, g: which ramp row, b: ring length, a: 255 = it cycles."""
index[y, x] = (start % ring, row, ring, 255)
def bake_fall(index, fall_mask, phase, ring, dash, kind_row):
"""Vertical streaks: each column has its own phase and ring, and the index climbs
one step every 3 px down, so the streaks slide down 3 px per step."""
for y, x in zip(*np.nonzero(fall_mask)):
bake_cell(index, y, x, y // 3 + phase[x], kind_row(x, dash[x]), ring[x])
def bake_pool_row(index, row_mask, fall_x, phase_left, phase_right, ring, ramp_row_id):
"""Horizontal dashes on one row of the pool: the index climbs every 3 px away from the
fall, so the dashes slide outward 3 px per step; the two sides start out of step."""
for y, x in zip(*np.nonzero(row_mask)):
phase = phase_left if x < fall_x else phase_right
bake_cell(index, y, x, abs(x - fall_x) // 3 + phase, ramp_row_id, ring)
Tested in Godot 4.6. Godot rendered the index map with the shader at 10 steps (0 to 137) with the Compatibility renderer and with Forward+, and every frame was compared with a Python version of the shader.
- Every pixel of every frame matches the Python version exactly, in both renderers.
- The Python version draws exactly the streaks and dashes of the clip at the top of this page, on all 90 steps of its loop, and where no streak is passing, the clip shows the plain body color.
- Rings in the index map are 12 to 19 entries long, and the ramp texture is 32 by 16 pixels.
Other engines
- Unity and others: the same shader works in any sprite shader. Import both textures with point filtering, no compression and no mipmaps, and read the ramp at exact texel centers.
- Old style palette hardware: if your engine has an indexed palette, you don't need the ramp texture at all. Rotate a range of palette entries every step, the way Deluxe Paint did.
Common pitfalls
A smoothed or compressed index map. If the engine filters or compresses the index texture on import, the numbers in it change and the rings break. Import it lossless with nearest filtering, and in Godot turn off process/fix_alpha_border, which rewrites the color of clear pixels.
HDR 2D. With HDR 2D on in Godot's project settings, the textures get converted from sRGB and the indices come out wrong. Keep it off for this.
Float math in the ring. mod(-42.0, 14.0) can come back as 14 instead of 0, one past the end of the ring. Do the ring math in integers.
Negative numbers in an integer mod. In GLSL, % with a negative number is undefined, and my first shader drew the wrong colors. Keep both sides positive: (start + ring - step % ring) % ring.
Every column in step. If all columns share one ring and one start, the streaks form flat bands that scroll like a texture. Give each column its own ring length and start.
Smooth steps. Blending between ring entries makes it look like a video filter. Whole steps only.
A clip that has to loop. A ring of 14 entries only repeats every 14 steps, so rings of different lengths don't line up again for a long time. In a game that doesn't matter. For a seamless video loop, pick ring lengths that divide the loop. Mine don't, so at the loop point every streak jumps once, which reads like any other step.
Where to next
- How to make a pixel art pond with reflections and ripples, the same idea of small layers, for water
- Pixel art day and night cycle with a color lookup table, another job for a palette texture
- How to add snow and ice to a 2D pixel art scene
- 8 Bit & '8 Bitish' Graphics-Outside the Box by Mark Ferrari, GDC 2016, on his color cycling scenes
- Color cycling on Wikipedia
- CanvasItem shaders in the Godot docs
Add this to your game with your coding agent
The prompt has the numbers, pseudo code, pitfalls and checks from this guide, written so your agent can fit it into your own project.
Copied. Want one of these every week?
The week's game techniques in one free email on Sunday, each with a prompt like this one.
# Add color cycled lava to my game
The lava in my 2D pixel art game is a flat tile that doesn't move. Make it flow with color cycling: the lava pixels keep their place and their colors rotate through short rings, one whole step at a time. Then add crust, light on the rock, a splash where a lava fall lands and embers.
Before you write code, look at my project: engine and language, pixel resolution and camera, how the lava is drawn now (a tilemap, one image, a fall and a pool), which rock stands in front of it, and how the game handles shaders. Keep my lava's shapes and colors where they work. Ask me before changing the art or adding a new rendering system.
## How it works
- Draw the flat look first: the fall as vertical stripes 2 to 4 px wide (dark red edges, orange middle, light orange core), the pool as flat bands by depth whose borders are sine waves rolling away from the fall on the same step clock.
- On top, a sprite whose texture is an index map: red = where in its ring the pixel starts, green = ramp row (a color pattern), blue = ring length, alpha = 255 if it cycles. Clear pixels show the flat look.
- A ring has a few colored entries and the rest clear, so a streak or dash passes and the body color shows again.
- The shader shows entry (start - step) mod ring, step = floor(time * 12). Whole steps only.
- Bake from masks: fall columns for streaks, some pool rows for dashes. The start moves one entry every 3 px along the flow (down the fall, away from the fall's center column `fall_x`). So the last entry of a ring leads: a streak's bright head is at its bottom, a dash's darker pixel at its front.
- Then the layers: crust, light on the rock, a foam crown where the fall lands, embers.
## Numbers that matter
Tested on a 480 x 270 side view scene, lava fall 64 px wide. Keep sizes in art pixels.
- Clock: 12 steps a second; every streak and dash moves 3 px a step.
- Fall: about 45% of the columns get a streak, each column with its own ring (12 to 18 entries) and start. Streaks are 2 to 4 entries (6 to 12 px), 1 px wide.
- Pool: dashes on the rows 4, 7, 12, 17, 24, 31 and 38 px below the surface, each row with its own ring (13 to 19), a dash of 2 to 4 bright entries plus 1 darker, and different starts left and right of the fall.
- Ramp texture: 32 x 16 px. Rows hold color patterns only; ring lengths live in the index map, so rows can be shared.
- Colors: #1e0c16 outline, #3e1a20 #622826 crust, #b0281c #de481e reds, #f67422 #fc922c #ffb238 oranges, #ffde60 #fff0a0 yellows, #fffadc white hot.
- Streak tail / head: edge #f67422 / #fc922c, middle #fc922c / #ffb238, core #ffde60 / #fffadc. Dash bright / darker: rows 4, 7 #ffde60 / #ffb238; rows 12, 17 #ffb238 / #f67422; rows 24, 31 #f67422 / #de481e; row 38 #de481e / #b0281c.
- Bands and crest: formulas in the pseudo code.
- Crust: a dark skin about 2 px wide along the banks, 5 hand-placed pieces on the surface away from the fall, each with a 1 px outline, lighter top, one red crack, bobbing 1 px.
- Light on rock: blur the lava shape, cut into 3 bands, move each rock pixel toward a red-brown version of its own shade by 85%, 60%, 35%. Skip lava and anything that glows itself.
- Splash: the fall flares out over its last 14 px into a foam crown 83 px wide, at most 11 px above the surface, lower half under it. A white line on the surface beside it, a ripple every 1.25 s, 40 droplets per 7.5 s.
- Embers: 34 per 7.5 s, 2 x 2 px yellow while young, then 1 px fading through orange to red.
## Pseudo code
```
# flat look, per step k; d = depth below surface, dx = abs(x - fall_x), wave(c) = 2 pi c k / 90
crest = clamp(round(1.4 + 1.6 sin(0.24 dx - wave(15))), 0, 3) # px above the surface
w2 = round(1.5 sin(0.11 dx - wave(6) + 1))
band = #ffb238 if d < 4 + round(sin(0.16 dx - wave(9)))
#fc922c if d < 10 + w2, #f67422 if d < 18 + w2
#de481e if d < 29 + round(2 sin(0.08 dx - wave(3) + 2)), else #b0281c
# bake, once
ramp_row(colors) = 32 RGBA, colors first, the rest clear
fall_ring(tail, head, dash) = ramp_row([tail] * (dash - 1) + [head])
pool_ring(hi, lo, dash) = ramp_row([hi] * dash + [lo])
for each fall column x with a streak:
ring[x] = random 12..18; dash[x] = random 2..4; phase[x] = random
for each fall pixel y: index[y, x] = ((y // 3 + phase[x]) mod ring[x], row of (stripe, dash), ring[x], 255)
for each dash row r:
ring = random 13..19; dash = random 2..4; phase_left, phase_right = random
for each pool pixel x on row surface + r:
phase = phase_left if x < fall_x else phase_right
index[y, x] = ((dx // 3 + phase) mod ring, row of r, ring, 255)
# shader, per index pixel
if alpha == 0: discard
start, row, ring = round(r * 255), round(g * 255), round(b * 255)
step = floor(time * 12)
i = (start + ring - step mod ring) mod ring # integers, all operands positive
color = ramp texel (i, row) # exact texel, no filtering
```
Godot: `canvas_item` shader, `texelFetch(ramps, ivec2(i, row), 0)`. Unity: sprite shader, point sampling, integer math. With an indexed palette: rotate palette ranges instead.
## Pitfalls
- A filtered, compressed or sRGB-converted index map breaks the rings. Import lossless, nearest, no mipmaps; in Godot also turn off `process/fix_alpha_border` and keep HDR 2D off.
- A float `mod` can return the ring length itself (`mod(-42.0, 14.0)` gave 14), and an integer `%` of a negative number is undefined in GLSL. Use the form above.
- One shared ring and start for all columns makes bands that scroll like a texture.
- Streaks wider than the pool's detail make the fall look like bigger pixels.
- Blending between entries looks like a video filter.
- Rock in front of the pool: cut the lava at the rock and let a stream run on underneath, with a dark line under the rock.
## Check that it works
- A pixel with ring length L looks the same at step s and s + L. For a seamless video loop, use ring lengths that divide the loop.
- Between two steps every streak moves exactly 3 px down and every dash 3 px away from the fall.
- No lava color appears that isn't in the bands or the ramp texture.
- Render the shader at a few steps and compare with a CPU version: every pixel equal. Godot needs a window for this (`--write-movie`).
- With the cycling sprite hidden, the flat look is unchanged.
## Art it needs
The cycling needs masks of the lava and your lava colors. If the lava is painted into a scene, you need a background without it:
- Paint the lava out by hand, or
- If the SpriteCook MCP tools are available in this session, edit the scene with "remove all the lava and its glow, keep everything else exactly the same" for a clean plate, and use the difference as the lava mask. Generate scenes at the model's native grid (480 x 268 for 16:9) or re-sample the raw output on its grid, then snap the plate to a small palette so the rock stays crisp.
Source: SpriteCook (2D game assets made by your coding agent, for Claude, ChatGPT and Cursor)
Full guide with pictures, the clip and tested Godot code: https://www.spritecook.ai/blog/pixel-art-lava-color-cyclingMore game techniques
All techniques
How 2D parallax scrolling works, with endless layersA parallax background is a stack of flat pictures that each follow part of the camera's movement. The one formula, scroll speeds for 15 layers, endless layers by repeating or recycling chunks, zoom parallax, Godot's built-in Parallax2D and tested code.
7 platformer tricks for slopes, one-way platforms, walls and crumbling blocksThe jump gets all the attention, but most platformer jank comes from what you stand on. Seven small tricks for crumbling blocks, falling blocks, one-way platforms, slopes, tight gaps, wall slides and climbing over ledges, with Celeste's numbers, tested Godot code and a prompt for each.
9 health bar tricks for a 2D game, from HP text to a bar that liesNine health bar tricks stacked on one fight, from plain HP text to a smooth drain, a damage trail, shake and flash, a heal trail, color by health, a low HP warning and a last sliver that lasts longer than it looks. With the timing numbers and tested Godot code.

