---
name: studio-pixel-tilemaps
description: Create a seamless pixel-art tileset and atlas (terrain, autotile/blob or Wang transitions, variants) with Aseprite or Pillow, verify seams with a composed test map, and import into Godot, Unity, Tiled or Phaser. Use for "make a tileset", "pixel tilemap", "autotile terrain", "tile atlas".
version: "1.1.0"
category: gamedev
platforms: [CLAUDE_CODE, CURSOR, CODEX_CLI]
---

# Pixel-art tilemaps

A tileset is a contract: tile size, atlas layout, palette and which edges must match. Get the contract right and the art is replaceable; get it wrong and every map breaks. This skill produces an atlas, a test map that proves the seams, and engine-ready import settings.

## When to use

- Terrain sets (grass, dirt, water, stone) with transitions for a 2D game.
- Dungeon or interior wall sets, platformer ground sets, overworld maps.
- Converting loose tiles into one atlas with documented indices.

## Agree on inputs first

| Decision          | Common choices                                                                                             |
| ----------------- | ---------------------------------------------------------------------------------------------------------- |
| Tile size         | 16x16 (most common), 8x8, 32x32; 2:1 iso tiles 32x16 or 64x32                                              |
| Palette           | Fixed 16 to 32 colors (e.g. a Lospec palette); hex list documented                                         |
| Transition scheme | 16-tile Wang corner set (minimal), 47-tile blob (full 8-neighbor), Godot terrain "Match Corners and Sides" |
| Atlas layout      | Columns count, row-major index = row * columns + col                                                       |
| Padding / spacing | 0 for pixel-perfect engines; 1 to 2 px extruded margin when the engine samples with filtering or mipmaps   |
| Target engine     | Godot 4, Unity, Tiled, LDtk, Phaser                                                                        |

## Toolchain

- **Aseprite** (CLI for packing): `aseprite -b tiles/*.png --sheet atlas.png --sheet-type rows --sheet-columns 8 --data atlas.json --format json-array`. Aseprite 1.3+ also has tilemap layers for drawing directly.
- **Python Pillow** for procedural generation, packing, palette enforcement and seam checks.
- **Tiled** or **LDtk** for building the test map; both export JSON engines can read.
- Alternatives: Pyxel Edit, LibreSprite, `tile-extruder` (npm) for extruding margins.

## Workflow

### 1. Base tile and edge contract

Draw the base terrain tile so it tiles with itself. Check by previewing 3x3 copies; Aseprite has View > Tiled Mode. Rules:

- Avoid strong features touching edges; put details in the interior 10x10 of a 16x16 tile.
- Break the grid with shapes that cross tile edges in a way that matches the opposite edge (left column continues into the right column).
- Use 1 to 2 hue-shifted ramps (shadows cooler, highlights warmer) rather than pure darker and lighter versions.

### 2. Variants

Make 2 to 4 variants of the base with identical edge pixels (top row, bottom row, left column, right column) and different interiors. Engines randomize these, which hides repetition. Keep high-contrast details rare (one variant with a flower, weighted low).

### 3. Transitions

- **Wang 16 (corner)**: each tile is defined by 4 corners being terrain A or B. 2^4 = 16 tiles cover every case. Fastest to make.
- **Blob 47**: covers inner corners precisely; needed when edges have a distinct border (cliff lips, outlined paths).
- Draw transitions on top of the base tile so the shared texture continues under the border.

### 4. Pack with Pillow

```python
from PIL import Image
import glob, json
T, COLS = 16, 8
tiles = sorted(glob.glob("tiles/*.png"))
rows = -(-len(tiles) // COLS)
atlas = Image.new("RGBA", (COLS * T, rows * T), (0, 0, 0, 0))
index = {}
for i, path in enumerate(tiles):
    im = Image.open(path).convert("RGBA")
    assert im.size == (T, T), f"{path} is {im.size}"
    atlas.paste(im, ((i % COLS) * T, (i // COLS) * T))
    index[path.split("/")[-1][:-4]] = i
atlas.save("atlas.png", optimize=True)
json.dump({"tile": T, "columns": COLS, "order": "row-major", "tiles": index}, open("atlas.json", "w"), indent=1)
```

Optional extrusion for filtered engines: `npx tile-extruder --tileWidth 16 --tileHeight 16 --input atlas.png --output atlas-extruded.png` (adds a 1 px margin and spacing of 2 by default; set margin and spacing accordingly in the engine).

### 5. Test map

Build a map that includes: a large repeated base area (at least 12x12) to expose repetition, straight edges in all four directions, outer and inner corners, a single isolated tile, diagonals, and a narrow 1-tile-wide strip. Render it:

```python
import random
random.seed(7)
grid = [[...]]  # tile indices from a terrain solver or a hand-authored layout
m = Image.new("RGBA", (len(grid[0]) * T, len(grid) * T))
for y, row in enumerate(grid):
    for x, idx in enumerate(row):
        sx, sy = (idx % COLS) * T, (idx // COLS) * T
        m.paste(atlas.crop((sx, sy, sx + T, sy + T)), (x * T, y * T))
m.resize((m.width * 4, m.height * 4), Image.NEAREST).save("testmap_4x.png")
```

### 6. Engine import

- **Godot 4**: Import tab, Texture > Filter: Nearest (or Project Settings > Rendering > Textures > Default Texture Filter = Nearest), Mipmaps off. Create a TileSet with Tile Size 16x16, add the atlas, set Separation and Texture Region Margins if extruded. Define Terrain Sets for auto-tiling. Turn on Rendering > 2D > Snap 2D Transforms to Pixel.
- **Unity**: Texture Type Sprite (2D and UI), Sprite Mode Multiple, Pixels Per Unit = 16, Filter Mode Point (no filter), Compression None, Generate Mip Maps off. Slice Grid By Cell Size 16x16. Use Pixel Perfect Camera. Rule Tiles (2D Tilemap Extras) for autotiling.
- **Tiled**: New Tileset, tile 16x16, margin and spacing matching the atlas. Terrain via Wang Sets.
- **Phaser 3**: `this.load.image('tiles', 'atlas.png')`, `map.addTilesetImage('name', 'tiles', 16, 16, margin, spacing)`, game config `pixelArt: true`.

## Common variants

- **Isometric tiles**: 2:1 diamonds (32x16 top face); atlas cells can be taller (32x32) for wall height; set Tile Layout to diamond in the engine.
- **Animated tiles** (water, torches): 4 to 8 frames in a row, documented frame duration (e.g. 150 ms). Godot: Animation Columns and Frames on the atlas tile.
- **Night or seasonal palette swap**: keep indices identical and swap palette, so maps reuse the same data.
- **Overlay layer**: decorative transparent tiles (grass tufts, cracks) on a second layer, never baked into base tiles.

## Quality checks

- Atlas dimensions are exact multiples of tile size (plus margins if extruded): `python -c "from PIL import Image; w,h=Image.open('atlas.png').size; print(w%16, h%16)"` prints `0 0`.
- Palette: `len(Image.open('atlas.png').convert('RGBA').getcolors(1<<16))` is at most the palette size plus transparent. No stray anti-aliased colors.
- No semi-transparent pixels unless intended: every alpha value is 0 or 255.
- Seam check in code: for each declared matching pair, assert the right column of A equals the left column of B (and top/bottom) pixel for pixel.
- Visual: test map viewed at 1x and integer zooms (2x, 3x, 4x); no visible grid, no lone pixel lines at edges, repetition not obvious in the 12x12 area at 1x.
- In engine: no bleeding lines between tiles while the camera moves at sub-pixel speeds.

## Pitfalls and fixes

| Problem                                  | Fix                                                                                       |
| ---------------------------------------- | ----------------------------------------------------------------------------------------- |
| Blurry tiles                             | Filter not set to Nearest/Point; mipmaps on; non-integer scale                            |
| Thin lines between tiles while scrolling | Texture bleeding; extrude tiles and set spacing, or snap camera to pixels                 |
| Obvious grid pattern                     | Features on edges, too few variants, high-contrast detail repeated; add weighted variants |
| Wrong tile chosen by autotile            | Index order or terrain bitmask mismatch; document and test every case in the test map     |
| Colors shift after export                | Color profile or indexed conversion; export RGBA PNG without color management             |
| Atlas off by one row                     | Padding added accidentally by the packer; use `--sheet-type rows`, not packed, and verify sizes         |

## Deliverables

- [ ] `atlas.png` at native resolution, plus extruded version if needed
- [ ] `atlas.json` (tile size, columns, margin, spacing, row-major index map, terrain bitmasks)
- [ ] Palette file (.hex or .gpl)
- [ ] Test map PNG at 1x and 4x nearest-neighbor
- [ ] Engine import notes (filter, PPU, tile size, terrain setup) and a sample scene or map file

[Moonlit Tiles reference](https://skills-hub.ai/showcases/projects/moonlit-tiles)
