Log inGet started
World

Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash

README.md

autotile

The tile atlas layout every twoDKit tile set shares, and 47-tile "blob" autotiling: given which of a solid cell's eight neighbours are also solid, it picks the atlas tile with the right edges, outer corners and inner corners. Pure data and maths, no engine calls.

Used by twoDKit.level to choose tiles when it builds a level's mesh, and by the tile set generator (twoDKit.artgen.tilesets) to paint each cell. Read it when you draw your own tile set atlas so it lines up.

Atlas layout

8 columns x 8 rows of 16 x 16 pixel cells (a 128 x 128 image), cell index = row * 8 + column counted from the top-left.

CellsHolds
0..46ground, one tile per blob mask: cell i is drawn for Autotile.masks[i + 1]
47back wall (BACKWALL), a darker fill drawn behind the level
48..51one-way platform: left end, middle, right end, single (ONEWAY.left/mid/right/single)
52..55spikes pointing up, down, left, right (SPIKES.up/down/left/right)
56..63eight decorations standing on the floor below them (DECOR_FIRST, DECOR_COUNT)

Neighbour mask

A bit is set when that neighbour is solid ground: N = 1, NE = 2, E = 4, SE = 8, S = 16, SW = 32, W = 64, NW = 128 (also exported as Autotile.N ... Autotile.NW). A clear cardinal bit is an exposed edge. A diagonal bit only counts when both cardinals beside it are set; N and E solid with NE empty is an inner-corner notch.

API

  • TILE (16), COLUMNS (8), ROWS (8): atlas geometry.
  • reduce(mask): drop every diagonal bit whose two cardinals are not both set (256 masks become 47).
  • masks: the 47 reduced masks in ascending order.
  • index(mask): atlas cell for any of the 256 raw masks.
  • open(mask, bit): true when that side is exposed (the neighbour is empty).
  • cellOrigin(index, tile?): pixel (x, y) of a cell's top-left corner.
  • cellUv(index): u0, v0, u1, v1 of a cell, v growing downward.
local Autotile = require("twoDKit.autotile")
local mask = Autotile.N + Autotile.E + Autotile.NE   -- ground above and to the right
local cell = Autotile.index(mask)
local u0, v0, u1, v1 = Autotile.cellUv(cell)