If you pack 16×16 or 32×32 pixel-art sprites edge-to-edge on a sprite sheet, everything looks clean at 1× integer zoom—until the camera scrolls at a fractional position, a sprite scales slightly, or a tilemap rotates.
Suddenly, 1px hairline seams flicker around tiles and characters: neighboring frame pixels leak in, or dark gray fringes outline every transparent edge.
The culprit is GPU UV sampling. Even with nearest-neighbor filtering (CanvasItem.TEXTURE_FILTER_NEAREST in Godot 4 or FilterMode.Point in Unity), floating-point texture coordinates at (u = x / W) can straddle a texel boundary by 1e-6, pulling samples from an adjacent sprite—or from rgba(0, 0, 0, 0) transparent gutter texels when mipmaps or bilinear taps are active.
Fixing this cleanly requires two things in your atlas pipeline: 1px edge-extrude bleed and MaxRects-BSSF packing.
1. Pattern 1: 1px Edge-Extrude Bleed (Why Transparent Padding Still Fringes)
Leaving a 1px or 2px empty (rgba(0, 0, 0, 0)) gap stops neighboring sprites from bleeding, but does not stop dark halos. When an engine samples across a sprite border into transparent black (#00000000) without premultiplied alpha—or during mipmap downsampling—RGB interpolates toward 0,0,0 while alpha drops to 0.5, producing a dirty black seam.
Edge extrusion solves both problems: before placing padding, duplicate the sprite's outermost 1px top, bottom, left, and right edges—plus the 4 corner pixels—outward into a 1px gutter. That way, any sub-texel overshoot lands on identical edge texels.
Here is a compact HTML5 Canvas drawExtrudedSprite() helper:
export function drawExtrudedSprite(ctx, img, sx, sy, sw, sh, dx, dy, extrude = 1) { // 1. Center sprite body ctx.drawImage(img, sx, sy, sw, sh, dx, dy, sw, sh); if (extrude <= 0) return; // 2. Top & bottom 1px edge strips extruded outward ctx.drawImage(img, sx, sy, sw, 1, dx, dy - extrude, sw, extrude); ctx.drawImage(img, sx, sy + sh - 1, sw, 1, dx, dy + sh, sw, extrude); // 3. Left & right 1px edge strips extruded outward ctx.drawImage(img, sx, sy, 1, sh, dx - extrude, dy, extrude, sh); ctx.drawImage(img, sx + sw - 1, sy, 1, sh, dx + sw, dy, extrude, sh); // 4. Four 1x1 corner pixels extended into corner gutter squares ctx.drawImage(img, sx, sy, 1, 1, dx - extrude, dy - extrude, extrude, extrude); ctx.drawImage(img, sx + sw - 1, sy, 1, 1, dx + sw, dy - extrude, extrude, extrude); ctx.drawImage(img, sx, sy + sh - 1, 1, 1, dx - extrude, dy + sh, extrude, extrude); ctx.drawImage(img, sx + sw - 1, sy + sh - 1, 1, 1, dx + sw, dy + sh, extrude, extrude); } Crucial detail: Set ctx.imageSmoothingEnabled = false on your destination atlas context, and ensure your exported engine metadata points to (dx, dy, sw, sh)—not the extruded outer bounds—so the engine renders only the true sprite rect while keeping the extruded 1px margin strictly as a UV safety buffer.
2. Pattern 2: MaxRects-BSSF Bin Packing + Unity Bottom-Left Y Conversion
Naive Shelf (Next-Fit) packers sort sprites by height and lay them left-to-right in horizontal rows. As soon as one 24×32 boss sprite shares a sheet with 16×16 tiles, every subsequent 16×16 row wastes half its vertical strip—forcing 12–16 trimmed sprites into a 128×128 Power-of-Two (POT) texture instead of fitting tightly inside 128×64.
MaxRects Best Short Side Fit (BSSF) maintains a list of maximal free rectangles. Whenever a padded+extruded sprite (pw = sw + 2 * (pad + extrude)) is placed:
- Score every free rectangle
rbyshortSideFit = Math.min(r.w - pw, r.h - ph)(tie-breaking onlongSideFit). - Split every overlapping free rectangle into up to 4 non-overlapping sub-rectangles (left, right, top, bottom).
- Prune any free rectangle completely contained inside another.
export function packMaxRectsBSSF(items, atlasW, atlasH) { let free = [{ x: 0, y: 0, w: atlasW, h: atlasH }]; const placed = []; for (const item of items) { let best = null; let bestShort = Infinity; let bestLong = Infinity; for (const r of free) { if (item.pw <= r.w && item.ph <= r.h) { const left = r.w - item.pw; const top = r.h - item.ph; const shortSide = Math.min(left, top); const longSide = Math.max(left, top); if (shortSide < bestShort || (shortSide === bestShort && longSide < bestLong)) { best = { x: r.x, y: r.y, w: item.pw, h: item.ph }; bestShort = shortSide; bestLong = longSide; } } } if (!best) return null; // Try next Power-of-Two size // Split overlapping free rects & prune contained ones const nextFree = []; for (const r of free) { if (best.x >= r.x + r.w || best.x + best.w <= r.x || best.y >= r.y + r.h || best.y + best.h <= r.y) { nextFree.push(r); continue; } if (best.x > r.x) nextFree.push({ x: r.x, y: r.y, w: best.x - r.x, h: r.h }); if (best.x + best.w < r.x + r.w) nextFree.push({ x: best.x + best.w, y: r.y, w: r.x + r.w - (best.x + best.w), h: r.h }); if (best.y > r.y) nextFree.push({ x: r.x, y: r.y, w: r.w, h: best.y - r.y }); if (best.y + best.h < r.y + r.h) nextFree.push({ x: r.x, y: best.y + best.h, w: r.w, h: r.y + r.h - (best.y + best.h) }); } free = nextFree.filter((a, i) => !nextFree.some((b, j) => i !== j && a.x >= b.x && a.y >= b.y && a.x + a.w <= b.x + b.w && a.y + a.h <= b.y + b.h)); placed.push({ ...item, x: best.x, y: best.y }); } return placed; } Top-Left Canvas Y vs Unity Bottom-Left SpriteMetaData Y
HTML5 Canvas, Godot 4 (Rect2), and Phaser all place (0, 0) at the top-left. Unity SpriteMetaData places (0, 0) at the bottom-left. Skipping that conversion flips every sprite slice vertically on import:
const godotRect = { x: frameX, y: frameY, w: sw, h: sh }; const unityRect = { x: frameX, y: atlasHeight - (frameY + sh), w: sw, h: sh }; 3. Exporting Godot 4 .tres SpriteFrames & Unity / Phaser JSON In-Browser
Because Godot 4 .tres files are plain-text INI-like resources, your browser packer can emit a ready-to-drop SpriteFrames or AtlasTexture resource referencing the packed POT .png directly:
[gd_resource type="SpriteFrames" load_steps=4 format=3] [ext_resource type="Texture2D" path="res://sprites/hero_atlas.png" id="1_atlas"] [sub_resource type="AtlasTexture" id="AtlasTexture_idle_0"] atlas = ExtResource("1_atlas") region = Rect2(2, 2, 16, 16) [resource] animations = [{ "frames": [{ "duration": 1.0, "texture": SubResource("AtlasTexture_idle_0") }], "loop": true, "name": &"idle", "speed": 8.0 }] Pair this with TextureImporter (spritePivot, bottom-left rect) in a .json descriptor for Unity Editor scripts or standard frames hash JSON for Phaser 3.
4. Try Both Pixel RPG Tools Live in Your Browser (Zero Login, 100% Local)
- AtlasPack 2D Sprite Sheet & Texture Atlas Packer (Free): Drop PNG sprites (never uploaded), toggle MaxRects-BSSF vs Shelf, 1px/2px edge-extrude bleed, trim transparent bounds, and download clean POT
.png+ Godot 4.tres/ Unity.json/ Phaser.jsonat https://nino-demos.pages.dev/atlaspack/ - TileCraft 16x16 Pixel RPG Auto-Tile Map Painter (Free): Paint maps with 4-bit cardinal bitmask auto-tiling and export PNG + Tiled
.tmjat https://nino-demos.pages.dev/tilecraft/ - VerdantRealm 16x16 Pixel RPG Tileset ($7.20 Launch Week -20%, reg $9): https://vietanh1109a.itch.io/verdantrealm-16x16-pixel-rpg-tileset
- GodotCore 4 Action-RPG Starter Kit ($15.20 Launch Week -20%): https://vietanh1109a.itch.io/godotcore-4-action-rpg-starter-kit
- All 67 Free Zero-Login Browser Dev & Game Tools: https://nino-demos.pages.dev/
