mwg API
    Preparing search index...

    Function loadTiledMap

    • Builds a TileMap from parsed Tiled JSON and sprite sheets already cut to tile size.

      A single sheet keeps the old behaviour: the map must have exactly one tileset, and cells hold plain frame indices (gid - firstgid). Several sheets - one per tileset, embedded or external - load a map mixing tilesets: each gid is owned by the tileset with the greatest firstgid at or below it (Tiled's own rule), and cells hold tileFrame packs naming the owning sheet. Every sheet must be cut to the map's own tile size, since one grid of cells draws them all.

      Resolving an external tileset stays the caller's job - the map only names its source, and fetching it is asset loading, which this pure parser never does.

      Parameters

      Returns LoadedTiledMap

      import { loadTiledMap, SpriteSheet, type TiledMapData, type TiledTilesetData, type TilesetSheet } from '@datamoc/mw_games/two-d/render';
      import * as Resources from '@datamoc/mw_games/assets';

      const map: TiledMapData = Resources.get('maps/village.json');
      const sheets: TilesetSheet[] = map.tilesets.map((ref) => {
      if (ref.source === undefined) {
      return { firstgid: ref.firstgid, sheet: SpriteSheet.grid('tiles/ground.png', map.tilewidth, map.tileheight) };
      }
      const tileset: TiledTilesetData = Resources.get(ref.source);
      return { firstgid: ref.firstgid, sheet: SpriteSheet.grid(tileset.image, tileset.tilewidth, tileset.tileheight) };
      });

      const { map: tileMap, objects } = loadTiledMap(map, sheets);
      console.log(objects[0]?.tileX); // an objectgroup entry's tile coordinate, if the map has one