Skip to main content
Version: Phaser v4.0.0

Phaser.Tilemaps.Parsers.Tiled

Scope: static

Source: src/tilemaps/parsers/tiled/index.js#L7

Static functions

AssignTileProperties

<static> AssignTileProperties(mapData)

Description:

Iterates over all tiles in every layer of the given MapData and synchronizes each tile with its parent tileset. For each valid tile, this function ensures the tile's dimensions match those defined by its tileset (which is important for maps that use multiple tilesets with different tile sizes), and then merges any custom properties defined for that tile type in the tileset onto the tile instance. This is called as part of the Tiled map parsing pipeline to ensure that per-tile-type metadata exported from the Tiled editor is available on the individual tile objects at runtime.

Parameters:

nametypeoptionaldescription
mapDataPhaser.Tilemaps.MapDataNoThe Map Data object.

Source: src/tilemaps/parsers/tiled/AssignTileProperties.js#L9
Since: 3.0.0


Base64Decode

<static> Base64Decode(data)

Description:

Decodes a base-64 encoded string, as used by Tiled when exporting tilemap layer data with base-64 encoding. The binary data is interpreted as a sequence of little-endian unsigned 32-bit integers, each representing a tile GID (Global Tile ID) in the layer.

Parameters:

nametypeoptionaldescription
dataobjectNoThe base-64 encoded string to decode.

Returns: array - Array of unsigned 32-bit integers representing the decoded tile GIDs.

Source: src/tilemaps/parsers/tiled/Base64Decode.js#L7
Since: 3.0.0


BuildTilesetIndex

<static> BuildTilesetIndex(mapData)

Description:

Builds a lookup index that maps each global tile ID (GID) to its pixel position within its tileset image and the index of that tileset within the map data. The returned array is sparse, keyed by GID, where each entry is a three-element array of the form [x, y, tilesetIndex]. The x and y values are the pixel coordinates of the top-left corner of the tile within its tileset image, accounting for tile margin and spacing. Any image collections in the map data are also converted into Tileset objects and added to mapData.tilesets before the index is built.

Parameters:

nametypeoptionaldescription
mapDataPhaser.Tilemaps.MapData | Phaser.Tilemaps.TilemapNoThe Map Data object.

Returns: array - A sparse array keyed by global tile ID (GID), where each entry is [x, y, tilesetIndex].

Source: src/tilemaps/parsers/tiled/BuildTilesetIndex.js#L9
Since: 3.0.0


CreateGroupLayer

<static> CreateGroupLayer(json, [group], [parentState])

Description:

Parses a Tiled group layer and builds an inherited state object for use when processing its child layers. Group layers in Tiled can nest other layers and accumulate properties such as name prefix, opacity, visibility, and positional offset. This function combines the given group's own properties with those of its parent state to produce a new state that child layers will inherit.

If no group is provided, a default root state is returned with neutral values (full opacity, visible, zero offset), suitable for use at the top level of the layer hierarchy.

Parameters:

nametypeoptionaldescription
jsonobjectNoThe Tiled JSON object.
groupobjectYesThe current group layer from the Tiled JSON file.
parentStateobjectYesThe inherited state of the parent group, as returned by a previous call to this function. Required when group is provided.

Returns: object - A group state object containing the accumulated name prefix, opacity, visibility, and x/y position offsets for use when parsing child layers.

Source: src/tilemaps/parsers/tiled/CreateGroupLayer.js#L9
Since: 3.21.0


ParseGID

<static> ParseGID(gid)

Description:

Parses a Tiled Global Tile ID (GID), extracting the tile index and any flip flags encoded in the high bits of the value. In the Tiled TMX format, the top three bits of a GID are used to indicate horizontal flip, vertical flip, and anti-diagonal flip (i.e. 90-degree rotation).

This function strips those flag bits from the GID to recover the raw tile index, then interprets all eight possible combinations of the three flags and converts them into a rotation value (in radians) and a boolean flipped state that Phaser can apply directly to a tile when rendering.

See the Tiled documentation on tile flipping for the full flag specification: http://docs.mapeditor.org/en/latest/reference/tmx-map-format/

Parameters:

nametypeoptionaldescription
gidnumberNoA Tiled GID, potentially with flip flags encoded in the high bits.

Returns: Phaser.Types.Tilemaps.GIDData - A GIDData object containing the raw tile index, the three individual flip flags, and the derived rotation (in radians) and flipped state.

Source: src/tilemaps/parsers/tiled/ParseGID.js#L11
Since: 3.0.0


ParseImageLayers

<static> ParseImageLayers(json)

Description:

Parses a Tiled JSON object and extracts all image layers, including those nested inside group layers. Each image layer is returned as a plain object with its name, image source, computed position (accounting for group and layer offsets), combined opacity, visibility, and custom properties inherited from the Tiled layer definition.

Parameters:

nametypeoptionaldescription
jsonobjectNoThe Tiled JSON object.

Returns: array - An array of objects, one per image layer, each containing name, image, x, y, alpha, visible, and properties fields.

Source: src/tilemaps/parsers/tiled/ParseImageLayers.js#L10
Since: 3.0.0


ParseJSONTiled

<static> ParseJSONTiled(name, source, insertNull)

Description:

Parses a Tiled JSON object into a new MapData object. The source JSON is deep copied before processing. This function handles orthogonal, isometric, staggered, and hexagonal map orientations. For hexagonal maps it also calculates the pixel dimensions based on the hex side length and stagger axis. It parses all tile layers, image layers, object layers, and tilesets found in the JSON, builds the tileset index, and assigns custom tile properties before returning the fully populated MapData instance.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the tilemap, used to set the name on the MapData.
sourceobjectNoThe original Tiled JSON object. This is deep copied by this function.
insertNullbooleanNoControls how empty tiles, tiles with an index of -1, in the map data are handled. If true, empty locations will get a value of null. If false, empty location will get a Tile object with an index of -1. If you have a large sparsely populated map and the tile data doesn't need to change then setting this value to true will help with memory consumption. However if your map is small or you need to update the tiles dynamically, then leave the default value set.

Returns: Phaser.Tilemaps.MapData - The created MapData object, or null if the data can't be parsed.

Source: src/tilemaps/parsers/tiled/ParseJSONTiled.js#L19
Since: 3.0.0


ParseObject

<static> ParseObject(tiledObject, [offsetX], [offsetY])

Description:

Convert a Tiled object to an internal parsed object normalising and copying properties over, while applying optional x and y offsets. The parsed object will always have the properties id, name, type, rotation, properties, visible, x, y, width and height. Other properties will be added according to the object type (such as text, polyline, gid etc.)

Parameters:

nametypeoptionaldefaultdescription
tiledObjectobjectNoThe raw Tiled object data, as exported from the Tiled map editor.
offsetXnumberYes0Optional additional offset to apply to the object's x property. Defaults to 0.
offsetYnumberYes0Optional additional offset to apply to the object's y property. Defaults to 0.

Returns: object - The parsed object containing properties read from the Tiled object according to its type with x and y values updated according to the given offsets.

Source: src/tilemaps/parsers/tiled/ParseObject.js#L14
Since: 3.0.0


ParseObjectLayers

<static> ParseObjectLayers(json)

Description:

Parses all object layers from a Tiled JSON tilemap into an array of ObjectLayer objects.

Iterates through every layer in the map, including layers nested inside Tiled group layers, and converts each objectgroup type layer into an ObjectLayer instance. Opacity and visibility values are inherited from parent group layers and multiplied down to their children. Non-object layers (tile layers, image layers, etc.) and non-objectgroup group members are skipped. The resulting array contains one entry per object layer found at any depth of nesting.

Parameters:

nametypeoptionaldescription
jsonobjectNoThe Tiled JSON object.

Returns: array - An array of all object layers in the tilemap as ObjectLayers.

Source: src/tilemaps/parsers/tiled/ParseObjectLayers.js#L12
Since: 3.0.0


ParseTileLayers

<static> ParseTileLayers(json, insertNull)

Description:

Parses all tile layers from a Tiled JSON object and returns them as an array of LayerData objects. Each tile layer in the JSON becomes one LayerData instance populated with Tile objects.

The function walks the full layer hierarchy, descending into Tiled group layers so that nested tile layers are included. Group transform properties (offset, opacity, visibility) are accumulated and applied to every child layer. Compressed tile data is not supported and any compressed layer will be skipped with a console warning. Layers encoded as uncompressed Base64 are decoded automatically before processing.

Both finite and infinite (chunked) Tiled maps are handled. For hexagonal maps the stagger axis, stagger index, and hex side length are read from the JSON and stored on each LayerData, and the pixel dimensions of the layer are calculated accordingly.

Each tile's flip flags and rotation are derived from the GID bit-packing that Tiled uses, so FlippedHorizontal, FlippedVertical, and FlippedAntiDiagonal are translated into the tile's flipX and rotation properties.

Parameters:

nametypeoptionaldescription
jsonobjectNoThe Tiled JSON object.
insertNullbooleanNoControls how empty tiles, tiles with an index of -1, in the map data are handled (see {@link Phaser.Tilemaps.Parsers.Tiled.ParseJSONTiled}).

Returns: Array.<Phaser.Tilemaps.LayerData> - - An array of LayerData objects, one for each entry in

json.layers with the type 'tilelayer'.

Source: src/tilemaps/parsers/tiled/ParseTileLayers.js#L16
Since: 3.0.0


ParseTilesets

<static> ParseTilesets(json)

Description:

Parses the tilesets and image collections from a Tiled JSON map, converting them into Phaser Tileset and ImageCollection instances. Handles both Tiled 1.x and Tiled 2.x formats, including per-tile properties, object groups, animation data, Wang sets, and typed tiles. External tilesets (those with a source property) are not supported and will produce a warning.

Parameters:

nametypeoptionaldescription
jsonobjectNoThe Tiled JSON data.

Returns: object - An object containing the tileset and image collection data.

Source: src/tilemaps/parsers/tiled/ParseTilesets.js#L12
Since: 3.0.0


ParseWangsets

<static> ParseWangsets(wangsets, datas)

Description:

Parses out the Wangset information from Tiled 1.1.5+ map data, if present.

Since a given tile can be in more than one wangset, the resulting properties are nested. tile.data.wangid[someWangsetName] will return the array-based wang id in this implementation.

Note that we're not guaranteed that there will be any 'normal' tiles if the only things in the tileset are wangtile definitions, so this has to be parsed separately.

See https://doc.mapeditor.org/en/latest/manual/using-wang-tiles/ for more information.

Parameters:

nametypeoptionaldescription
wangsetsArray.<object>NoThe array of wangset objects (parsed from JSON)
datasobjectNoThe object into which wangset data from Tiled is stored, keyed by tile ID.

Source: src/tilemaps/parsers/tiled/ParseWangsets.js#L7
Since: 3.53.0