nape-js API
    Preparing search index...

    Function meshTilemap

    • Convert a 2D grid of tile values into the minimal set of axis-aligned rectangles that cover the solid cells, using the requested merge strategy.

      The result is geometry-only — no Body or Shape is created — which makes this function reusable for debug overlays, rendering, or custom body construction. buildTilemapBody is a thin wrapper that converts the rectangles to Polygon shapes.

      Greedy meshing reduces shape count dramatically for typical platformer maps. A 50-tile floor strip becomes one rectangle; a solid 10x10 block becomes one rectangle instead of 100. Fewer shapes = smaller broadphase footprint, faster narrowphase, less debug-draw work.

      Parameters

      Returns TilemapRect[]

      The list of merged rectangles in tile coordinates.

      const rects = meshTilemap([
      [1, 1, 1, 0, 1],
      [1, 1, 1, 0, 1],
      [0, 0, 0, 0, 1],
      ]);
      // -> [{x:0,y:0,w:3,h:2}, {x:4,y:0,w:1,h:3}]