PrefabManager08 / 15

A prefab for repeated elements

Create a cell from a JSON template.

Add the prefab JSON to the asset manifest. Call spawnPrefab on the container and pass the new cell’s name and coordinates. To remove the cell before the container is removed, call await spawned.dispose().

const spawned = await this.node.spawnPrefab({
  prefabId: 'json/prefabs/game/block-cell.json',
  localId: 'tile-0',
  overrides: { visible: true, x: 24, y: 24 },
});
const tile = spawned.node;
One cellboard-cell.json
→
64 separate nodes · 8 × 8 board

Sources ↗

Block Puzzle · block-cell.json↗The JSON template for a tile.