mwg API
    Preparing search index...

    Function autotileFrames

    • One frame per cell of a terrain, autotiled from a same-terrain test alone.

      Parameters

      • width: number
      • height: number
      • sameTerrain: (x: number, y: number) => boolean

        called for every cell in range, and for the 8 neighbours around each - including cells outside width/height, so a caller wanting a hard map edge should have it return false there rather than relying on this to bounds-check

      • frames: readonly number[]

        the 47 frames a blobIndex of 0 to 46 selects between, drawn (or arranged) against BLOB_SHAPES

      Returns Int32Array

      one frame index per cell, row-major, EMPTY wherever sameTerrain is false

      import { autotileFrames, BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';

      const water = new Set([0, 1, 10, 11]); // a 2x2 pond in a wider grid
      const frames = Array.from({ length: BLOB_SHAPES.length }, (_, index) => index); // frame N = shape N

      const cellFrames = autotileFrames(10, 10, (x, y) => water.has(y * 10 + x), frames);
      console.log(cellFrames[0]); // the blob frame for the pond's top-left corner