Derived from src/cocos/tiledmap/tiled-map.ts, src/cocos/tiledmap/tiled-layer.ts, src/cocos/tiledmap/tiled-object-group.ts, src/cocos/tiledmap/tiled-types.ts, src/cocos/tiledmap/tiled-tile.ts, src/cocos/tiledmap/assembler/simple.ts, src/cocos/2d/framework/ui-renderer.ts, examples/tiledmap-basic/main.js, docs/notes/tiled-map-notes.md, docs/manual/tiled-culling-and-dirty-state.md, docs/manual/tiled-object-queries.md, build/cocosair.module.js (as of 2026-10-10).
What it does
TiledMap renders a TMX map built entirely at run time from strings and sprite frames - there is no
Creator importer and no uuid graph. The bundle export block of build/cocosair.module.js (currently
:161574) carries TiledMap, TiledMapAsset, TiledLayer, TiledObjectGroup, TiledTile and
TiledUserNodeData. Layers and object groups are ordinary UIRenderer batched nodes, so they
inherit the UI camera and the markForUpdateRenderData dirty machinery.
Construction chain (a bag of parallel arrays)
_applyFile zips spriteFrameNames, spriteFrameSizes and spriteFrames into lookup maps, zips
tsxFileNames with tsxFiles[i].text, then hands tmxXmlStr to TMXMapInfo
(src/cocos/tiledmap/tiled-map.ts:340-388, tsx map :375-380, parse call :382). A tileset whose
sourceImage has no matching frame logs warnID(16406, i) (:478) and drops those tiles.
tmxAsset assignment is what builds the layer nodes (src/cocos/tiledmap/tiled-map.ts:104-110),
and __preload applies lazily only if an asset was set before enable (:327), so assign the asset
first. TiledMap.enableCulling fans the value out to every layer (:125-131) and layer-level
enableCulling marks render data directly (src/cocos/tiledmap/tiled-layer.ts:229-236).
The refresh ladder (culling dirty is not render-data dirty)
setTileGIDAt(gid, x, y, flags)masks the flipped bits off the incoming gid (src/cocos/tiledmap/tiled-layer.ts:693-694), throws on an out-of-range cell (:699), andflagsis the fourth argument (:711).- Single-cell and rectangle writes share
_updateTileForGID, which updates tile data, marks culling state dirty and schedules the renderer. The UI renderer queue deduplicates the layer within a frame. - The assembler calls
updateCulling()first, then rebuilds based on dirty state, animation, TiledNodes and transform changes. Culling recalculates the visible rectangle only when enabled. - Both setters update an active static layer on the next render even with culling off or a stationary camera. TSX animation still uses its independent native ticking path.
Object queries and coordinate rewriting
getObjectsByType('solid')matches the TMXclass(legacytype) string, while a number matches theTMXObjectTypeenum (src/cocos/tiledmap/tiled-object-group.ts:179,classNamedeclared atsrc/cocos/tiledmap/tiled-types.ts:454).getRawObjects()returns frozen snapshots of the original TMX numbers (src/cocos/tiledmap/tiled-object-group.ts:174, built at:259-260) because_initrewritesobject.xandobject.yin place and keeps the originals only inobject.offset(:263-284, ortho flip:284, isometric divisortileSize.height:276-283).- Only TEXT and IMAGE objects get child nodes (
src/cocos/tiledmap/tiled-object-group.ts:286-300); RECT, ELLIPSE, POLYGON and POLYLINE stay pure data. TiledTileexposes the cell through agridaccessor, notgid(src/cocos/tiledmap/tiled-tile.ts:109-118).
Gotchas
setCullingDirty(true)only sets a flag. Use the tile setters to edit cells and schedule a refresh; no manual reactivation is needed.- Passing
flagsin the third position mis-throws or drops flip bits; the signature order is(gid, x, y, flags)(src/cocos/tiledmap/tiled-layer.ts:711). - Trusting
object.xafter_initgives the rewritten engine coordinate, not the authored TMX value; readgetRawObjects()for the original (src/cocos/tiledmap/tiled-object-group.ts:174).