Phaser.Tilemaps
ParseToTilemap
staticParseToTilemap(scene, [key], [tileWidth], [tileHeight], [width], [height], [data], [insertNull])
Description:
Create a Tilemap from the given key or data. If neither is given, make a blank Tilemap. When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When parsing from a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the map data. For an empty map, you should specify tileWidth, tileHeight, width & height.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to which this Tilemap belongs. | |
| key | string | Yes | The key in the Phaser cache that corresponds to the loaded tilemap data. | |
| tileWidth | number | Yes | 32 | The width of a tile in pixels. |
| tileHeight | number | Yes | 32 | The height of a tile in pixels. |
| width | number | Yes | 10 | The width of the map in tiles. |
| height | number | Yes | 10 | The height of the map in tiles. |
| data | Array.<Array.<number>> | Yes | Instead of loading from the cache, you can also load directly from a 2D array of tile indexes. | |
| insertNull | boolean | Yes | false | Controls 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 locations 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.Tilemap - The Tilemap object created from the given data.
Source: src/tilemaps/ParseToTilemap.js#L12
Since: 3.0.0
Phaser.Tilemaps.Components
CalculateFacesAt
staticCalculateFacesAt(tileX, tileY, layer)
Description:
Calculates interesting faces at the given tile coordinates of the specified layer. Interesting faces are used internally for optimizing collisions against tiles. This method is mostly used internally to optimize recalculating faces when only one tile has been changed.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate of the tile in tile grid coordinates. |
| tileY | number | No | The y coordinate of the tile in tile grid coordinates. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The tile at the given coordinates, or null if no tile exists there.
Source: src/tilemaps/components/CalculateFacesAt.js#L9
Since: 3.0.0
CalculateFacesWithin
staticCalculateFacesWithin(tileX, tileY, width, height, layer)
Description:
Calculates the interesting faces for all collidable tiles within the rectangular area specified (in tile coordinates) of the layer. An "interesting face" is an exposed edge of a collidable tile — specifically, any face that is not shared with another collidable tile adjacent to it. For example, if two collidable tiles sit side by side, the shared edge between them is not an interesting face because a physics body moving between them would never collide with it. Only interesting faces are tested during collision resolution, which avoids the internal-edge problem and keeps collision checks efficient. This function is called automatically when tiles are placed or removed, and is mostly used internally by the tilemap system.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/CalculateFacesWithin.js#L10
Since: 3.0.0
CheckIsoBounds
staticCheckIsoBounds(tileX, tileY, layer, [camera])
Description:
Checks if the given tile coordinate is within the visible bounds of the camera for an isometric tilemap layer. This is used during tile culling to determine whether a tile should be rendered.
The tile coordinate is first converted to world-space using the layer's tile-to-world transform. The resulting position is then tested against the camera's world view rectangle, expanded by the layer's cullPaddingX and cullPaddingY values (in tile units) to avoid tiles popping in at the edges of the viewport. The padding offsets are measured from the center of each tile.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to check against. |
| camera | Phaser.Cameras.Scene2D.Camera | Yes | The Camera to run the cull check against. |
Returns: boolean - Returns true if the coordinates are within the iso bounds.
Source: src/tilemaps/components/CheckIsoBounds.js#L11
Since: 3.50.0
Copy
staticCopy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
Description:
Copies the tiles in the source rectangular area to a new destination (all specified in tile coordinates) within the layer. This copies all tile properties and recalculates collision information in the destination region.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| srcTileX | number | No | The x coordinate of the area to copy from, in tiles, not pixels. |
| srcTileY | number | No | The y coordinate of the area to copy from, in tiles, not pixels. |
| width | number | No | The width of the area to copy, in tiles, not pixels. |
| height | number | No | The height of the area to copy, in tiles, not pixels. |
| destTileX | number | No | The x coordinate of the area to copy to, in tiles, not pixels. |
| destTileY | number | No | The y coordinate of the area to copy to, in tiles, not pixels. |
| recalculateFaces | boolean | No | true if the collision face data for tiles in the destination region should be recalculated after the copy. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/Copy.js#L12
Since: 3.0.0
CreateFromTiles
staticCreateFromTiles(indexes, replacements, spriteConfig, scene, camera, layer)
Description:
Creates a Sprite for every object matching the given tile indexes in the layer. You can optionally specify if each tile will be replaced with a new tile after the Sprite has been created. This is useful if you want to lay down special tiles in a level that are converted to Sprites, but want to replace the tile itself with a floor tile or similar once converted.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| indexes | number | Array.<number> | No | The tile index, or array of indexes, to create Sprites from. |
| replacements | number | Array.<number> | No | The tile index, or array of indexes, to change a converted tile to. Set to null to leave the tiles unchanged. If an array is given, it is assumed to be a one-to-one mapping with the indexes array. |
| spriteConfig | Phaser.Types.GameObjects.Sprite.SpriteConfig | No | The config object to pass into the Sprite creator (i.e. scene.make.sprite). |
| scene | Phaser.Scene | No | The Scene to create the Sprites within. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when determining the world XY position of each tile. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.GameObjects.Sprite> - An array of the Sprites that were created.
Source: src/tilemaps/components/CreateFromTiles.js#L11
Since: 3.0.0
CullBounds
staticCullBounds(layer, camera)
Description:
Calculates the tile coordinate bounds within the given orthogonal tilemap layer that fall inside the camera's viewport. The result accounts for the layer's position, scale, and cull padding on each axis. This is used internally by the cull tiles function to determine which tiles need to be rendered.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. |
Returns: Phaser.Geom.Rectangle - A rectangle containing the culled bounds. If you wish to retain this object, clone it, as it's recycled internally.
Source: src/tilemaps/components/CullBounds.js#L13
Since: 3.50.0
CullTiles
staticCullTiles(layer, camera, [outputArray], [renderOrder])
Description:
Returns the tiles in the given layer that are within the camera's viewport. Culling avoids rendering tiles that are off-screen, improving performance. The camera's world view bounds are calculated and snapped to the scaled tile size, taking cull padding (expressed in tiles) into account. If the layer has skipCull enabled, or if its scroll factors differ from 1, the full layer dimensions are used instead so that all tiles are included. This function is used internally by the tilemap rendering pipeline.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. | |
| outputArray | array | Yes | An optional array to store the culled Tile objects within. | |
| renderOrder | number | Yes | 0 | The rendering order constant. Controls the order in which tiles are iterated and added to the output array. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects.
Source: src/tilemaps/components/CullTiles.js#L10
Since: 3.50.0
Fill
staticFill(index, tileX, tileY, width, height, recalculateFaces, layer)
Description:
Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the specified index. Tiles will be set to collide if the given index is a colliding index. Collision information in the region will be recalculated.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| index | number | No | The tile index to fill the area with. |
| tileX | number | No | The left most tile coordinate (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile coordinate (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX coordinate the area will be. |
| height | number | No | How many tiles tall from the tileY coordinate the area will be. |
| recalculateFaces | boolean | No | true if the faces data should be recalculated. |
| layer | Phaser.Tilemaps.LayerData | No | The tile layer to use. If not given the current layer is used. |
Source: src/tilemaps/components/Fill.js#L11
Since: 3.0.0
FilterTiles
staticFilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Description:
For each tile in the given rectangular area (in tile coordinates) of the layer, run the given filter callback function. Any tiles that pass the filter test (i.e. where the callback returns true) will be returned as a new array. Similar to Array.prototype.filter in vanilla JS.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| callback | function | No | The callback. Each tile in the given area will be passed to this callback as the first and only parameter. The callback should return true for tiles that pass the filter. |
| context | object | No | The context under which the callback should be run. |
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area to filter. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area to filter. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Tilemaps.Tile> - The filtered array of Tiles.
Source: src/tilemaps/components/FilterTiles.js#L9
Since: 3.0.0
FindByIndex
staticFindByIndex(index, skip, reverse, layer)
Description:
Searches the entire map layer for the first tile matching the given index, then returns that Tile object. If no match is found, it returns null. The search starts from the top-left tile and continues horizontally until it hits the end of the row, then it drops down to the next row. If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to the top-left.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| index | number | No | The tile index value to search for. |
| skip | number | No | The number of times to skip a matching tile before returning. |
| reverse | boolean | No | If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The first (or n skipped) tile with the matching index.
Source: src/tilemaps/components/FindByIndex.js#L7
Since: 3.0.0
FindTile
staticFindTile(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Description:
Find the first tile in the given rectangular area (in tile coordinates) of the layer that satisfies the provided testing function. I.e. finds the first tile for which callback returns true. Similar to Array.prototype.find in vanilla JS.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| callback | FindTileCallback | No | The callback. Each tile in the given area will be passed to this callback as the first parameter, along with the tile index and the array of tiles. |
| context | object | No | The context under which the callback should be run. |
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area to filter. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area to filter. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - A Tile that matches the search, or null if no Tile found
Source: src/tilemaps/components/FindTile.js#L19
Since: 3.0.0
ForEachTile
staticForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Description:
For each tile in the given rectangular area (in tile coordinates) of the layer, run the given callback. Similar to Array.prototype.forEach in vanilla JS.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| callback | EachTileCallback | No | The callback. Each tile in the given area will be passed to this callback, along with its index in the array and the array itself. |
| context | object | No | The context under which the callback should be run. |
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area to filter. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area to filter. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/ForEachTile.js#L17
Since: 3.0.0
GetCullTilesFunction
staticGetCullTilesFunction(orientation)
Description:
Gets the correct function to use to cull tiles, based on the map orientation.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to cull tiles for the given map type.
Source: src/tilemaps/components/GetCullTilesFunction.js#L14
Since: 3.50.0
GetTileAt
staticGetTileAt(tileX, tileY, nonNull, layer)
Description:
Gets a tile at the given tile coordinates from the given layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | X position to get the tile from (given in tile units, not pixels). |
| tileY | number | No | Y position to get the tile from (given in tile units, not pixels). |
| nonNull | boolean | No | For empty tiles, return a Tile object with an index of -1 instead of null. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The tile at the given coordinates or null if no tile was found or the coordinates were invalid.
Source: src/tilemaps/components/GetTileAt.js#L9
Since: 3.0.0
GetTileAtWorldXY
staticGetTileAtWorldXY(worldX, worldY, nonNull, camera, layer)
Description:
Gets a tile at the given world coordinates from the given layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | X position to get the tile from (given in pixels) |
| worldY | number | No | Y position to get the tile from (given in pixels) |
| nonNull | boolean | No | For empty tiles, return a Tile object with an index of -1 instead of null. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The tile at the given coordinates or null if no tile was found or the coordinates were invalid.
Source: src/tilemaps/components/GetTileAtWorldXY.js#L12
Since: 3.0.0
GetTileCorners
staticGetTileCorners(tileX, tileY, camera, layer)
Description:
Gets the four corners of a tile, given its tile-space coordinates, as an array of world-space Vector2 positions. The returned positions account for the layer's world position, scale, and the camera's scroll offset, and are ordered: top-left, top-right, bottom-right, bottom-left.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera whose scroll offset is used when calculating the world-space position of the tile corners. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Math.Vector2> - An array of Vector2s corresponding to the world XY location of each tile corner.
Source: src/tilemaps/components/GetTileCorners.js#L9
Since: 3.60.0
GetTileCornersFunction
staticGetTileCornersFunction(orientation)
Description:
Gets the correct function to use to get the tile corners, based on the map orientation.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to get the tile corners for the given map orientation.
Source: src/tilemaps/components/GetTileCornersFunction.js#L12
Since: 3.60.0
GetTileToWorldXFunction
staticGetTileToWorldXFunction(orientation)
Description:
Returns the correct function to use for converting a tile X coordinate to a world X pixel coordinate, based on the map orientation. For orthogonal maps, this returns the TileToWorldX function. For all other orientations, a NOOP function is returned, as non-orthogonal maps do not support this conversion.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to convert tile X coordinates to world X pixel coordinates for the given map orientation.
Source: src/tilemaps/components/GetTileToWorldXFunction.js#L11
Since: 3.50.0
GetTileToWorldXYFunction
staticGetTileToWorldXYFunction(orientation)
Description:
Gets the correct function to use to translate tiles, based on the map orientation.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to translate tiles for the given map type.
Source: src/tilemaps/components/GetTileToWorldXYFunction.js#L14
Since: 3.50.0
GetTileToWorldYFunction
staticGetTileToWorldYFunction(orientation)
Description:
Gets the correct function to use to translate tiles, based on the map orientation.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to translate tiles for the given map type.
Source: src/tilemaps/components/GetTileToWorldYFunction.js#L12
Since: 3.50.0
GetTilesWithin
staticGetTilesWithin(tileX, tileY, width, height, filteringOptions, layer)
Description:
Gets the tiles in the given rectangular area (in tile coordinates) of the layer.
This returns an array containing references to the Tile instances themselves, so be aware that modifying them directly will affect the layer data.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Tilemaps.Tile> - Array of Tile objects.
Source: src/tilemaps/components/GetTilesWithin.js#L9
Since: 3.0.0
GetTilesWithinShape
staticGetTilesWithinShape(shape, filteringOptions, camera, layer)
Description:
Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, Line, Rectangle or Triangle. The shape should be in world coordinates.
Note: This method currently only works with orthogonal tilemap layers.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| shape | Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects that intersect with the given shape, or an empty array if no tiles overlap or the layer is not orthogonal.
Source: src/tilemaps/components/GetTilesWithinShape.js#L23
Since: 3.0.0
GetTilesWithinWorldXY
staticGetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer)
Description:
Gets the tiles in the given rectangular area (in world coordinates) of the layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The world x coordinate for the top-left of the area. |
| worldY | number | No | The world y coordinate for the top-left of the area. |
| width | number | No | The width of the area. |
| height | number | No | The height of the area. |
| filteringOptions | Phaser.Types.Tilemaps.FilteringOptions | No | Optional filters to apply when getting the tiles. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when factoring in which tiles to return. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Tilemaps.Tile> - Array of Tile objects.
Source: src/tilemaps/components/GetTilesWithinWorldXY.js#L13
Since: 3.0.0
GetWorldToTileXFunction
staticGetWorldToTileXFunction(orientation)
Description:
Returns the correct function to use for converting a world pixel X coordinate to a tile X (column) index, based on the map orientation. Only orthogonal maps support this conversion; for all other orientations a NULL function is returned.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to convert a world X coordinate to a tile X index for the given map orientation, or a NULL function if the orientation is unsupported.
Source: src/tilemaps/components/GetWorldToTileXFunction.js#L11
Since: 3.50.0
GetWorldToTileXYFunction
staticGetWorldToTileXYFunction(orientation)
Description:
Returns the appropriate world-to-tile coordinate conversion function for the given map orientation. The returned function converts world pixel coordinates (X, Y) into tile grid coordinates, using the correct projection math for orthogonal, isometric, hexagonal, or staggered tilemaps. If the orientation is unrecognised, a NOOP function is returned.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant, as defined in Phaser.Tilemaps.ORIENTATION_CONST. |
Returns: function - The world-to-tile coordinate conversion function for the given map orientation.
Source: src/tilemaps/components/GetWorldToTileXYFunction.js#L14
Since: 3.50.0
GetWorldToTileYFunction
staticGetWorldToTileYFunction(orientation)
Description:
Returns the correct function to use for converting a world Y coordinate to a tile Y coordinate, based on the map orientation. Returns WorldToTileY for orthogonal maps, StaggeredWorldToTileY for staggered maps, and a NULL function for all other orientations.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | number | No | The Tilemap orientation constant. |
Returns: function - The function to use to convert a world Y coordinate to a tile Y coordinate for the given map orientation.
Source: src/tilemaps/components/GetWorldToTileYFunction.js#L12
Since: 3.50.0
HasTileAt
staticHasTileAt(tileX, tileY, layer)
Description:
Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns false if there is no tile or if the tile at that location has an index of -1.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | X position to get the tile from (given in tile units, not pixels). |
| tileY | number | No | Y position to get the tile from (given in tile units, not pixels). |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: boolean - Returns true if a valid tile (with an index greater than -1) exists at the given coordinates, or false if the coordinates are out of bounds, the tile is null, or the tile index is -1.
Source: src/tilemaps/components/HasTileAt.js#L9
Since: 3.0.0
HasTileAtWorldXY
staticHasTileAtWorldXY(worldX, worldY, camera, layer)
Description:
Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns false if there is no tile or if the tile at that location has an index of -1.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The X coordinate of the world position. |
| worldY | number | No | The Y coordinate of the world position. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when factoring in which tiles to return. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: boolean - Returns a boolean, or null if the layer given was invalid.
Source: src/tilemaps/components/HasTileAtWorldXY.js#L12
Since: 3.0.0
HexagonalCullBounds
staticHexagonalCullBounds(layer, camera)
Description:
Calculates the tile grid index bounds of a hexagonal Tilemap Layer that fall within the camera's viewport. The bounds account for the layer's stagger axis (x or y), hex side length, tile scale, layer offset, and cull padding, returning the range of tile columns and rows that need to be rendered. This is used internally by the hexagonal cull tiles function.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. |
Returns: object - An object containing the left, right, top and bottom tile grid index bounds.
Source: src/tilemaps/components/HexagonalCullBounds.js#L10
Since: 3.50.0
HexagonalCullTiles
staticHexagonalCullTiles(layer, camera, [outputArray], [renderOrder])
Description:
Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. | |
| outputArray | array | Yes | An optional array to store the Tile objects within. | |
| renderOrder | number | Yes | 0 | The rendering order constant. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects.
Source: src/tilemaps/components/HexagonalCullTiles.js#L10
Since: 3.50.0
HexagonalGetTileCorners
staticHexagonalGetTileCorners(tileX, tileY, camera, layer)
Description:
Calculates and returns the six corner positions of a hexagonal tile as an array of Vector2 objects in world space. The tile is identified by its tile grid coordinates and the corners are computed relative to the tile's world center, taking into account the layer's stagger axis and any scale applied to the tilemap layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when converting tile coordinates to world position. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Array.<Phaser.Math.Vector2> - An array of Vector2s corresponding to the world XY location of each tile corner.
Source: src/tilemaps/components/HexagonalGetTileCorners.js#L12
Since: 3.60.0
HexagonalTileToWorldXY
staticHexagonalTileToWorldXY(tileX, tileY, point, camera, layer)
Description:
Converts from hexagonal tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the world coordinates from the tile values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in world coordinates.
Source: src/tilemaps/components/HexagonalTileToWorldXY.js#L9
Since: 3.50.0
HexagonalWorldToTileXY
staticHexagonalWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Description:
Converts from world XY coordinates (pixels) to hexagonal tile XY coordinates (tile units), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The x coordinate to be converted, in pixels, not tiles. |
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinates down to the nearest integer. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile XY coordinates from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in tile units.
Source: src/tilemaps/components/HexagonalWorldToTileXY.js#L9
Since: 3.50.0
IsInLayerBounds
staticIsInLayerBounds(tileX, tileY, layer)
Description:
Checks if the given tile coordinates are within the bounds of the layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: boolean - true if the tile coordinates are within the bounds of the layer, otherwise false.
Source: src/tilemaps/components/IsInLayerBounds.js#L7
Since: 3.0.0
IsometricCullTiles
staticIsometricCullTiles(layer, camera, [outputArray], [renderOrder])
Description:
Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. | |
| outputArray | array | Yes | An optional array to store the Tile objects within. | |
| renderOrder | number | Yes | 0 | The rendering order constant. 0 = right-down, 1 = left-down, 2 = right-up, 3 = left-up. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects.
Source: src/tilemaps/components/IsometricCullTiles.js#L9
Since: 3.50.0
IsometricTileToWorldXY
staticIsometricTileToWorldXY(tileX, tileY, point, camera, layer)
Description:
Converts from isometric tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the world position from the tile coordinates. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in world coordinates.
Source: src/tilemaps/components/IsometricTileToWorldXY.js#L9
Since: 3.50.0
IsometricWorldToTileXY
staticIsometricWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer, [originTop])
Description:
Converts from world XY coordinates (pixels) to isometric tile XY coordinates (tile units), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| worldX | number | No | The x coordinate to be converted, in pixels, not tiles. | |
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. | |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. | |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. | |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| originTop | boolean | Yes | true | Which is the active face of the isometric tile? The top (default, true), or the base? (false) |
Returns: Phaser.Math.Vector2 - The XY location in tile units.
Source: src/tilemaps/components/IsometricWorldToTileXY.js#L9
Since: 3.50.0
PutTileAt
staticPutTileAt(tile, tileX, tileY, recalculateFaces, layer)
Description:
Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified location. If you pass in an index, only the index at the specified location will be changed. Collision information will be recalculated at the specified location.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tile | number | Phaser.Tilemaps.Tile | No | The index of this tile to set or a Tile object. |
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| recalculateFaces | boolean | No | true if the faces data should be recalculated. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The Tile object that was created or added to this map.
Source: src/tilemaps/components/PutTileAt.js#L12
Since: 3.0.0
PutTileAtWorldXY
staticPutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer)
Description:
Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified location. If you pass in an index, only the index at the specified location will be changed. Collision face information will be recalculated at the specified location if recalculateFaces is true.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tile | number | Phaser.Tilemaps.Tile | No | The index of this tile to set or a Tile object. |
| worldX | number | No | The x coordinate, in pixels. |
| worldY | number | No | The y coordinate, in pixels. |
| recalculateFaces | boolean | No | true if the tile edge collision face data should be recalculated. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The Tile object that was created or added to this map.
Source: src/tilemaps/components/PutTileAtWorldXY.js#L12
Since: 3.0.0
PutTilesAt
staticPutTilesAt(tilesArray, tileX, tileY, recalculateFaces, layer)
Description:
Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, all attributes will be copied over to the specified location. If you pass in an index, only the index at the specified location will be changed. Collision information will be recalculated within the region tiles were changed.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tilesArray | Array.<number> | Array.<Array.<number>> | Array.<Phaser.Tilemaps.Tile> | Array.<Array.<Phaser.Tilemaps.Tile>> |
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| recalculateFaces | boolean | No | true if the faces data should be recalculated. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/PutTilesAt.js#L10
Since: 3.0.0
Randomize
staticRandomize(tileX, tileY, width, height, indexes, layer)
Description:
Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the specified layer. Each tile will receive a new index. If an array of indexes is passed in, then those will be used for randomly assigning new tile indexes. If an array is not provided, the indexes found within the region (excluding -1) will be used for randomly assigning new tile indexes. This method only modifies tile indexes and does not change collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The left-most tile coordinate (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top-most tile coordinate (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX coordinate the area will be. |
| height | number | No | How many tiles tall from the tileY coordinate the area will be. |
| indexes | Array.<number> | No | An array of indexes to randomly draw from during randomization. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/Randomize.js#L10
Since: 3.0.0
RemoveTileAt
staticRemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer)
Description:
Removes the tile at the given tile coordinates in the specified layer and updates the layer's collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate of the tile to remove, in tile grid units (not pixels). |
| tileY | number | No | The y coordinate of the tile to remove, in tile grid units (not pixels). |
| replaceWithNull | boolean | No | If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. |
| recalculateFaces | boolean | No | true if the faces data should be recalculated. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The Tile object that was removed.
Source: src/tilemaps/components/RemoveTileAt.js#L11
Since: 3.0.0
RemoveTileAtWorldXY
staticRemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer)
Description:
Removes the tile at the given world coordinates in the specified layer and updates the layer's collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The x coordinate, in pixels. |
| worldY | number | No | The y coordinate, in pixels. |
| replaceWithNull | boolean | No | If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. |
| recalculateFaces | boolean | No | true if the faces data should be recalculated. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Tilemaps.Tile - The Tile object that was removed.
Source: src/tilemaps/components/RemoveTileAtWorldXY.js#L12
Since: 3.0.0
RenderDebug
staticRenderDebug(graphics, styleConfig, layer)
Description:
Draws a debug representation of the layer to the given Graphics. This is helpful when you want to get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation wherever you want on the screen.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| graphics | Phaser.GameObjects.Graphics | No | The target Graphics object to draw upon. |
| styleConfig | Phaser.Types.Tilemaps.DebugStyleOptions | No | An object specifying the colors to use for the debug drawing. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/RenderDebug.js#L14
Since: 3.0.0
ReplaceByIndex
staticReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, layer)
Description:
Scans the given rectangular area (given in tile coordinates) for tiles with an index matching findIndex and updates their index to match newIndex. This only modifies the index and does not change collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| findIndex | number | No | The index of the tile to search for. |
| newIndex | number | No | The index of the tile to replace it with. |
| tileX | number | No | The left most tile coordinate (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile coordinate (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/ReplaceByIndex.js#L9
Since: 3.0.0
RunCull
staticRunCull(layer, bounds, renderOrder, outputArray)
Description:
Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
| bounds | object | No | An object containing the left, right, top and bottom bounds. |
| renderOrder | number | No | The rendering order constant. 0 = right-down, 1 = left-down, 2 = right-up, 3 = left-up. |
| outputArray | array | No | The array to store the Tile objects within. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects.
Source: src/tilemaps/components/RunCull.js#L7
Since: 3.50.0
SetCollision
staticSetCollision(indexes, collides, recalculateFaces, layer, [updateLayer])
Description:
Sets collision on the given tile or tiles within a layer by index. You can pass in either a single numeric index or an array of indexes: [2, 3, 15, 20]. The collides parameter controls if collision will be enabled (true) or disabled (false).
This function updates both the layer's collision index (which affects any tiles placed in the future) and, unless updateLayer is false, all existing tiles in the layer that match the given indexes.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| indexes | number | array | No | Either a single tile index, or an array of tile indexes. | |
| collides | boolean | No | If true it will enable collision. If false it will clear collision. | |
| recalculateFaces | boolean | No | Whether or not to recalculate the tile faces after the update. | |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| updateLayer | boolean | Yes | true | If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. |
Source: src/tilemaps/components/SetCollision.js#L11
Since: 3.0.0
SetCollisionBetween
staticSetCollisionBetween(start, stop, collides, recalculateFaces, layer, [updateLayer])
Description:
Sets collision on a range of tiles in a layer whose index is between the specified start and stop (inclusive). Calling this with a start value of 10 and a stop value of 14 would set collision for tiles 10, 11, 12, 13 and 14. The collides parameter controls if collision will be enabled (true) or disabled (false).
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| start | number | No | The first index of the tile to be set for collision. | |
| stop | number | No | The last index of the tile to be set for collision. | |
| collides | boolean | No | If true it will enable collision. If false it will clear collision. | |
| recalculateFaces | boolean | No | Whether or not to recalculate the tile faces after the update. | |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| updateLayer | boolean | Yes | true | If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. |
Source: src/tilemaps/components/SetCollisionBetween.js#L11
Since: 3.0.0
SetCollisionByExclusion
staticSetCollisionByExclusion(indexes, collides, recalculateFaces, layer)
Description:
Sets collision on all tiles in the given layer, except for tiles that have an index specified in the given array. The collides parameter controls if collision will be enabled (true) or disabled (false). Tile indexes not currently in the layer are not affected.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| indexes | Array.<number> | No | An array of tile indexes to exclude from the collision update. Tiles with these indexes will not have their collision state changed. |
| collides | boolean | No | If true it will enable collision. If false it will clear collision. |
| recalculateFaces | boolean | No | Whether or not to recalculate the tile faces after the update. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetCollisionByExclusion.js#L11
Since: 3.0.0
SetCollisionByProperty
staticSetCollisionByProperty(properties, collides, recalculateFaces, layer)
Description:
Sets collision on the tiles within a layer by checking tile properties. If a tile has a property that matches the given properties object, its collision flag will be set. The collides parameter controls if collision will be enabled (true) or disabled (false). Passing in { collides: true } would update the collision flag on any tiles with a "collides" property that has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can also use an array of values, e.g. { types: ["stone", "lava", "sand" ] }. If a tile has a "types" property that matches any of those values, its collision flag will be updated.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| properties | object | No | An object with tile properties and corresponding values that should be checked. |
| collides | boolean | No | If true it will enable collision. If false it will clear collision. |
| recalculateFaces | boolean | No | Whether or not to recalculate the tile faces after the update. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetCollisionByProperty.js#L11
Since: 3.0.0
SetCollisionFromCollisionGroup
staticSetCollisionFromCollisionGroup(collides, recalculateFaces, layer)
Description:
Sets collision on the tiles within a layer by checking each tile's collision group data (typically defined in Tiled within the tileset collision editor). If any objects are found within a tile's collision group, the tile's colliding information will be set. The collides parameter controls if collision will be enabled (true) or disabled (false).
Parameters:
| name | type | optional | description |
|---|---|---|---|
| collides | boolean | No | If true it will enable collision. If false it will clear collision. |
| recalculateFaces | boolean | No | Whether or not to recalculate the tile faces after the update. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetCollisionFromCollisionGroup.js#L10
Since: 3.0.0
SetLayerCollisionIndex
staticSetLayerCollisionIndex(tileIndex, collides, layer)
Description:
Internally used method to keep track of the tile indexes that collide within a layer. This updates LayerData.collideIndexes to either contain or not contain the given tileIndex.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileIndex | number | No | The tile index to set the collision boolean for. |
| collides | boolean | No | Should the tile index collide or not? |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetLayerCollisionIndex.js#L7
Since: 3.0.0
SetTileCollision
staticSetTileCollision(tile, [collides])
Description:
Internally used method to set the colliding state of a tile. This does not recalculate interesting faces.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| tile | Phaser.Tilemaps.Tile | No | The Tile to set the collision on. | |
| collides | boolean | Yes | true | Should the tile collide or not? |
Source: src/tilemaps/components/SetTileCollision.js#L7
Since: 3.0.0
SetTileIndexCallback
staticSetTileIndexCallback(indexes, callback, callbackContext, layer)
Description:
Sets a global collision callback for the given tile index within the layer. This will affect all tiles on this layer that have the same index. If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| indexes | number | array | No | Either a single tile index, or an array of tile indexes to have a collision callback set for. |
| callback | function | No | The callback that will be invoked when the tile is collided with. |
| callbackContext | object | No | The context under which the callback is called. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetTileIndexCallback.js#L7
Since: 3.0.0
SetTileLocationCallback
staticSetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, layer)
Description:
Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. If a callback is already set for a tile it will be replaced. Set the callback to null to remove it.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The left most tile coordinate to use as the origin of the area. |
| tileY | number | No | The top most tile coordinate to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| callback | function | No | The callback that will be invoked when the tile is collided with. |
| callbackContext | object | No | The context under which the callback is called. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SetTileLocationCallback.js#L9
Since: 3.0.0
Shuffle
staticShuffle(tileX, tileY, width, height, layer)
Description:
Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given layer. It will only randomize the tiles in that area, so if they're all the same nothing will appear to have changed! This method only modifies tile indexes and does not change collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The leftmost tile index (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The topmost tile index (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/Shuffle.js#L10
Since: 3.0.0
StaggeredCullBounds
staticStaggeredCullBounds(layer, camera)
Description:
Returns the bounds in the given layer that are within the camera's viewport. This is used internally by the cull tiles function.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. |
Returns: object - An object containing the left, right, top and bottom bounds.
Source: src/tilemaps/components/StaggeredCullBounds.js#L10
Since: 3.50.0
StaggeredCullTiles
staticStaggeredCullTiles(layer, camera, [outputArray], [renderOrder])
Description:
Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to run the cull check against. | |
| outputArray | array | Yes | An optional array to store the Tile objects within. | |
| renderOrder | number | Yes | 0 | The rendering order constant. |
Returns: Array.<Phaser.Tilemaps.Tile> - An array of Tile objects.
Source: src/tilemaps/components/StaggeredCullTiles.js#L10
Since: 3.50.0
StaggeredTileToWorldXY
staticStaggeredTileToWorldXY(tileX, tileY, point, camera, layer)
Description:
Converts from staggered tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the world position from the tile coordinates. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in world coordinates.
Source: src/tilemaps/components/StaggeredTileToWorldXY.js#L9
Since: 3.50.0
StaggeredTileToWorldY
staticStaggeredTileToWorldY(tileY, camera, layer)
Description:
Converts from staggered tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when factoring in scroll offset during the conversion. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The Y location in world coordinates.
Source: src/tilemaps/components/StaggeredTileToWorldY.js#L7
Since: 3.50.0
StaggeredWorldToTileXY
staticStaggeredWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Description:
Converts from world XY coordinates (pixels) to staggered tile XY coordinates (tile units), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The x coordinate to be converted, in pixels, not tiles. |
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in tile units.
Source: src/tilemaps/components/StaggeredWorldToTileXY.js#L9
Since: 3.50.0
StaggeredWorldToTileY
staticStaggeredWorldToTileY(worldY, snapToFloor, camera, layer)
Description:
Converts from world Y coordinates (pixels) to staggered tile Y coordinates (tile units), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The Y location in tile units.
Source: src/tilemaps/components/StaggeredWorldToTileY.js#L7
Since: 3.50.0
SwapByIndex
staticSwapByIndex(indexA, indexB, tileX, tileY, width, height, layer)
Description:
Scans the given rectangular area (given in tile coordinates) for tiles with an index matching indexA and swaps them with indexB. This only modifies the index and does not change collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| indexA | number | No | The tile index to search for and replace with indexB. |
| indexB | number | No | The tile index to replace indexA with. |
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/SwapByIndex.js#L9
Since: 3.0.0
TileToWorldX
staticTileToWorldX(tileX, camera, layer)
Description:
Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the world position from the tile coordinates. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The world X coordinate, in pixels, corresponding to the given tile X coordinate.
Source: src/tilemaps/components/TileToWorldX.js#L7
Since: 3.0.0
TileToWorldXY
staticTileToWorldXY(tileX, tileY, point, camera, layer)
Description:
Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The x coordinate, in tiles, not pixels. |
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when converting the tile coordinates to world pixel values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in world coordinates.
Source: src/tilemaps/components/TileToWorldXY.js#L11
Since: 3.0.0
TileToWorldY
staticTileToWorldY(tileY, camera, layer)
Description:
Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileY | number | No | The y coordinate, in tiles, not pixels. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The Y location in world coordinates.
Source: src/tilemaps/components/TileToWorldY.js#L7
Since: 3.0.0
WeightedRandomize
staticWeightedRandomize(tileX, tileY, width, height, weightedIndexes, layer)
Description:
Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the specified layer. Each tile will receive a new index. New indexes are drawn from the given weightedIndexes array. An example weighted array:
[ { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 { index: 26, weight: 0.5 } // Probability of index 26 would be 0.5 / 8 ]
The probability of any index being chosen is (the index's weight) / (sum of all weights). This method only modifies tile indexes and does not change collision information.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| tileX | number | No | The left most tile index (in tile coordinates) to use as the origin of the area. |
| tileY | number | No | The top most tile index (in tile coordinates) to use as the origin of the area. |
| width | number | No | How many tiles wide from the tileX index the area will be. |
| height | number | No | How many tiles tall from the tileY index the area will be. |
| weightedIndexes | Array.<object> | No | An array of objects to randomly draw from during randomization. They should be in the form: { index: 0, weight: 4 } or { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Source: src/tilemaps/components/WeightedRandomize.js#L10
Since: 3.0.0
WorldToTileX
staticWorldToTileX(worldX, snapToFloor, camera, layer)
Description:
Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The x coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The X location in tile units.
Source: src/tilemaps/components/WorldToTileX.js#L12
Since: 3.0.0
WorldToTileXY
staticWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Description:
Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the layer's position, scale and scroll. This will return a new Vector2 object or update the given point object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldX | number | No | The x coordinate to be converted, in pixels, not tiles. |
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. |
| point | Phaser.Math.Vector2 | No | A Vector2 to store the coordinates in. If not given a new Vector2 is created. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: Phaser.Math.Vector2 - The XY location in tile units.
Source: src/tilemaps/components/WorldToTileXY.js#L9
Since: 3.0.0
WorldToTileY
staticWorldToTileY(worldY, snapToFloor, camera, layer)
Description:
Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the layer's position, scale and scroll.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| worldY | number | No | The y coordinate to be converted, in pixels, not tiles. |
| snapToFloor | boolean | No | Whether or not to round the tile coordinate down to the nearest integer. |
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to use when calculating the tile index from the world values. |
| layer | Phaser.Tilemaps.LayerData | No | The Tilemap Layer to act upon. |
Returns: number - The Y location in tile units.
Source: src/tilemaps/components/WorldToTileY.js#L12
Since: 3.0.0
Phaser.Tilemaps.Parsers
FromOrientationString
staticFromOrientationString([orientation])
Description:
Converts a Tilemap orientation string into the corresponding Phaser.Tilemaps.OrientationType constant. Recognized values are 'isometric', 'staggered', and 'hexagonal'. Any other string, including 'orthogonal', will return the orthogonal orientation constant, which is the default grid-based orientation used by most tilemaps.
The comparison is case-insensitive.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| orientation | string | Yes | The orientation type as a string. |
Returns: Phaser.Tilemaps.OrientationType - The Tilemap Orientation type.
Source: src/tilemaps/parsers/FromOrientationString.js#L9
Since: 3.50.0
Parse
staticParse(name, mapFormat, data, tileWidth, tileHeight, insertNull)
Description:
Parses raw data of a given Tilemap format into a new MapData object. If no recognized data format is found, returns null. When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When parsing from a map from Tiled, the tileWidth & tileHeight will be pulled from the map data.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name of the tilemap, used to set the name on the MapData. |
| mapFormat | number | No | The format of the map data. Must be one of the Phaser.Tilemaps.Formats constants, such as Phaser.Tilemaps.Formats.TILED_JSON. |
| data | Array.<Array.<number>> | string | object | No |
| tileWidth | number | No | The width of a tile in pixels. Required for 2D array and CSV, but ignored for Tiled JSON. |
| tileHeight | number | No | The height of a tile in pixels. Required for 2D array and CSV, but ignored for Tiled JSON. |
| insertNull | boolean | No | Controls 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've 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 map format was not recognized.
Source: src/tilemaps/parsers/Parse.js#L13
Since: 3.0.0
Parse2DArray
staticParse2DArray(name, data, tileWidth, tileHeight, insertNull)
Description:
Parses a 2D array of tile indexes into a new MapData object with a single layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name of the tilemap, used to set the name on the MapData. |
| data | Array.<Array.<number>> | No | A 2D array of tile indexes. |
| tileWidth | number | No | The width of a tile in pixels. |
| tileHeight | number | No | The height of a tile in pixels. |
| insertNull | boolean | No | Controls 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 locations 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 MapData object.
Source: src/tilemaps/parsers/Parse2DArray.js#L12
Since: 3.0.0
ParseCSV
staticParseCSV(name, data, tileWidth, tileHeight, insertNull)
Description:
Parses a CSV string of tile indexes into a new MapData object with a single layer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name of the tilemap, used to set the name on the MapData. |
| data | string | No | CSV string of tile indexes. |
| tileWidth | number | No | The width of a tile in pixels. |
| tileHeight | number | No | The height of a tile in pixels. |
| insertNull | boolean | No | Controls 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've 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 resulting MapData object.
Source: src/tilemaps/parsers/ParseCSV.js#L10
Since: 3.0.0
Phaser.Tilemaps.Parsers.Impact
ParseTileLayers
staticParseTileLayers(json, insertNull)
Description:
Parses all tilemap layers in an Impact JSON object into new LayerData objects.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The Impact JSON object. |
| insertNull | boolean | No | Controls how empty tiles (those with an index of -1) are stored in the LayerData. If true, empty tile positions are stored as null. If false, a Tile object with an index of -1 is created for each empty position instead. |
Returns: Array.<Phaser.Tilemaps.LayerData> - - An array of LayerData objects, one for each entry in
json.layer.
Source: src/tilemaps/parsers/impact/ParseTileLayers.js#L10
Since: 3.0.0
ParseTilesets
staticParseTilesets(json)
Description:
Parses all unique tilesets from an Impact (Weltmeister) tilemap JSON object and returns them as an array of Tileset instances. Each layer in the JSON is inspected for a tileset name; duplicate names and collision layers (which have a blank tileset name) are ignored. Tile IDs within Impact tilesets are relative to the tileset rather than globally unique, and tilesets have no margin or padding, so each Tileset is created with those values set to zero.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The Impact JSON data. |
Returns: array - An array of Tilesets.
Source: src/tilemaps/parsers/impact/ParseTilesets.js#L9
Since: 3.0.0
ParseWeltmeister
staticParseWeltmeister(name, json, insertNull)
Description:
Parses a Weltmeister JSON object into a new MapData object.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name of the tilemap, used to set the name on the MapData. |
| json | object | No | The Weltmeister JSON object. |
| insertNull | boolean | No | Controls 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've 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/impact/ParseWeltmeister.js#L12
Since: 3.0.0
Phaser.Tilemaps.Parsers.Tiled
AssignTileProperties
staticAssignTileProperties(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:
| name | type | optional | description |
|---|---|---|---|
| mapData | Phaser.Tilemaps.MapData | No | The Map Data object. |
Source: src/tilemaps/parsers/tiled/AssignTileProperties.js#L9
Since: 3.0.0
Base64Decode
staticBase64Decode(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:
| name | type | optional | description |
|---|---|---|---|
| data | object | No | The 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
staticBuildTilesetIndex(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:
| name | type | optional | description |
|---|---|---|---|
| mapData | Phaser.Tilemaps.MapData | Phaser.Tilemaps.Tilemap | No | The 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
staticCreateGroupLayer(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:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The Tiled JSON object. |
| group | object | Yes | The current group layer from the Tiled JSON file. |
| parentState | object | Yes | The 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
staticParseGID(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:
| name | type | optional | description |
|---|---|---|---|
| gid | number | No | A 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
staticParseImageLayers(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:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The 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
staticParseJSONTiled(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:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name of the tilemap, used to set the name on the MapData. |
| source | object | No | The original Tiled JSON object. This is deep copied by this function. |
| insertNull | boolean | No | Controls 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
staticParseObject(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:
| name | type | optional | default | description |
|---|---|---|---|---|
| tiledObject | object | No | The raw Tiled object data, as exported from the Tiled map editor. | |
| offsetX | number | Yes | 0 | Optional additional offset to apply to the object's x property. Defaults to 0. |
| offsetY | number | Yes | 0 | Optional 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
staticParseObjectLayers(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:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The 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
staticParseTileLayers(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:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The Tiled JSON object. |
| insertNull | boolean | No | Controls 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
staticParseTilesets(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:
| name | type | optional | description |
|---|---|---|---|
| json | object | No | The 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
staticParseWangsets(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:
| name | type | optional | description |
|---|---|---|---|
| wangsets | Array.<object> | No | The array of wangset objects (parsed from JSON) |
| datas | object | No | The 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