Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: Components
Phaser.Tilemaps.Components

Methods

<static> CalculateFacesAt(tileX, tileY, layer)
Focus
Focus

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 description
tileX number

The x coordinate.

tileY number

The y coordinate.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> CalculateFacesWithin(tileX, tileY, width, height, layer)
Focus
Focus

Description:

Calculates interesting faces within the rectangular area specified (in tile coordinates) of the layer. Interesting faces are used internally for optimizing collisions against tiles. This method is mostly used internally.

Parameters:

name type description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> CheckIsoBounds(tileX, tileY, layer, [camera])
Focus
Focus

Description:

Checks if the given tile coordinate is within the isometric layer bounds, or not.

Parameters:

name type arguments description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to check against.

camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to run the cull check against.

Returns:
Description:

Returns true if the coordinates are within the iso bounds.

Type:
  • boolean
Examples:
Since: 3.50.0
Focus
Focus
<static> Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
Focus
Focus

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 & recalculates collision information in the destination region.

Parameters:

name type description
srcTileX number

The x coordinate of the area to copy from, in tiles, not pixels.

srcTileY number

The y coordinate of the area to copy from, in tiles, not pixels.

width number

The width of the area to copy, in tiles, not pixels.

height number

The height of the area to copy, in tiles, not pixels.

destTileX number

The x coordinate of the area to copy to, in tiles, not pixels.

destTileY number

The y coordinate of the area to copy to, in tiles, not pixels.

recalculateFaces boolean

true if the faces data should be recalculated.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> CreateFromTiles(indexes, replacements, spriteConfig, scene, camera, layer)
Focus
Focus

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 description
indexes number | Array.<number>

The tile index, or array of indexes, to create Sprites from.

replacements number | Array.<number>

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

The config object to pass into the Sprite creator (i.e. scene.make.sprite).

scene Phaser.Scene

The Scene to create the Sprites within.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when determining the world XY

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

An array of the Sprites that were created.

Examples:
Since: 3.0.0
Focus
Focus
<static> CullBounds(layer, camera)
Focus
Focus

Description:

Returns the bounds in the given orthogonal layer that are within the cameras viewport. This is used internally by the cull tiles function.

Parameters:

name type description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

Returns:
Description:

A rectangle containing the culled bounds. If you wish to retain this object, clone it, as it's recycled internally.

Examples:
Since: 3.50.0
Focus
Focus
<static> CullTiles(layer, camera, [outputArray], [renderOrder])
Focus
Focus

Description:

Returns the tiles in the given layer that are within the cameras viewport. This is used internally.

Parameters:

name type arguments description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

outputArray array <optional>

An optional array to store the Tile objects within.

renderOrder number <optional>

The rendering order constant.

Returns:
Description:

An array of Tile objects.

Type:
Examples:
Since: 3.50.0
Focus
Focus
<static> Fill(index, tileX, tileY, width, height, recalculateFaces, layer)
Focus
Focus

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 description
index number

The tile index to fill the area with.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

recalculateFaces boolean

true if the faces data should be recalculated.

layer Phaser.Tilemaps.LayerData

The tile layer to use. If not given the current layer is used.

Examples:
Since: 3.0.0
Focus
Focus
<static> FilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Focus
Focus

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 returned as a new array. Similar to Array.prototype.Filter in vanilla JS.

Parameters:

name type description
callback function

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

The context under which the callback should be run.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area to filter.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area to filter.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The filtered array of Tiles.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<static> FindByIndex(index, skip, reverse, layer)
Focus
Focus

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 column. If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to the top-left.

Parameters:

name type description
index number

The tile index value to search for.

skip number

The number of times to skip a matching tile before returning.

reverse boolean

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

The Tilemap Layer to act upon.

Returns:
Description:

The first (or n skipped) tile with the matching index.

Examples:
Since: 3.0.0
Focus
Focus
<static> FindTile(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Focus
Focus

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 description
callback FindTileCallback

The callback. Each tile in the given area will be passed to this callback as the first and only parameter.

context object

The context under which the callback should be run.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area to filter.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area to filter.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

A Tile that matches the search, or null if no Tile found

Examples:
Since: 3.0.0
Focus
Focus
<static> ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, layer)
Focus
Focus

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 description
callback EachTileCallback

The callback. Each tile in the given area will be passed to this callback as the first and only parameter.

context object

The context under which the callback should be run.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area to filter.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area to filter.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> GetCullTilesFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to cull tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to cull tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetTileAt(tileX, tileY, nonNull, layer)
Focus
Focus

Description:

Gets a tile at the given tile coordinates from the given layer.

Parameters:

name type description
tileX number

X position to get the tile from (given in tile units, not pixels).

tileY number

Y position to get the tile from (given in tile units, not pixels).

nonNull boolean

If true getTile won't return null for empty tiles, but a Tile object with an index of -1.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The tile at the given coordinates or null if no tile was found or the coordinates were invalid.

Examples:
Since: 3.0.0
Focus
Focus
<static> GetTileAtWorldXY(worldX, worldY, nonNull, camera, layer)
Focus
Focus

Description:

Gets a tile at the given world coordinates from the given layer.

Parameters:

name type description
worldX number

X position to get the tile from (given in pixels)

worldY number

Y position to get the tile from (given in pixels)

nonNull boolean

If true, function won't return null for empty tiles, but a Tile object with an index of -1.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The tile at the given coordinates or null if no tile was found or the coordinates were invalid.

Examples:
Since: 3.0.0
Focus
Focus
<static> GetTilesWithin(tileX, tileY, width, height, filteringOptions, layer)
Focus
Focus

Description:

Gets the tiles in the given rectangular area (in tile coordinates) of the layer.

Parameters:

name type description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

Array of Tile objects.

Type:
Examples:
Since: 3.0.0
Focus
Focus
<static> GetTilesWithinShape(shape, filteringOptions, camera, layer)
Focus
Focus

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.

Parameters:

name type description
shape Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle

A shape in world (pixel) coordinates

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

Array of Tile objects.

Type:
Examples:
Focus
Focus
<static> GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer)
Focus
Focus

Description:

Gets the tiles in the given rectangular area (in world coordinates) of the layer.

Parameters:

name type description
worldX number

The world x coordinate for the top-left of the area.

worldY number

The world y coordinate for the top-left of the area.

width number

The width of the area.

height number

The height of the area.

filteringOptions Phaser.Types.Tilemaps.FilteringOptions

Optional filters to apply when getting the tiles.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when factoring in which tiles to return.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

Array of Tile objects.

Type:
Examples:
Focus
Focus
<static> GetTileToWorldXFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetTileToWorldXYFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetTileToWorldYFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetWorldToTileXFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetWorldToTileXYFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> GetWorldToTileYFunction(orientation)
Focus
Focus

Description:

Gets the correct function to use to translate tiles, based on the map orientation.

Parameters:

name type description
orientation number

The Tilemap orientation constant.

Returns:
Description:

The function to use to translate tiles for the given map type.

Type:
  • function
Examples:
Focus
Focus
<static> HasTileAt(tileX, tileY, layer)
Focus
Focus

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 description
tileX number

X position to get the tile from (given in tile units, not pixels).

tileY number

Y position to get the tile from (given in tile units, not pixels).

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

Returns a boolean, or null if the layer given was invalid.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
<static> HasTileAtWorldXY(worldX, worldY, camera, layer)
Focus
Focus

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 description
worldX number

The X coordinate of the world position.

worldY number

The Y coordinate of the world position.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when factoring in which tiles to return.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

Returns a boolean, or null if the layer given was invalid.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
<static> HexagonalCullBounds(layer, camera)
Focus
Focus

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 description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

Returns:
Description:

An object containing the left, right, top and bottom bounds.

Type:
  • object
Examples:
Since: 3.50.0
Focus
Focus
<static> HexagonalCullTiles(layer, camera, [outputArray], [renderOrder])
Focus
Focus

Description:

Returns the tiles in the given layer that are within the cameras viewport. This is used internally.

Parameters:

name type arguments description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

outputArray array <optional>

An optional array to store the Tile objects within.

renderOrder number <optional>

The rendering order constant.

Returns:
Description:

An array of Tile objects.

Type:
Examples:
Since: 3.50.0
Focus
Focus
<static> HexagonalTileToWorldXY(tileX, tileY, point, camera, layer)
Focus
Focus

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 description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in world coordinates.

Examples:
Focus
Focus
<static> HexagonalTileToWorldY(tileY, camera, layer)
Focus
Focus

Description:

Converts from hexagonal tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the layer's position, scale and scroll.

Parameters:

name type description
tileY number

The y coordinate, in tiles, not pixels.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in world coordinates.

Type:
  • number
Examples:
Focus
Focus
<static> HexagonalWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Focus
Focus

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 description
worldX number

The x coordinate to be converted, in pixels, not tiles.

worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinates down to the nearest integer.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in tile units.

Examples:
Focus
Focus
<static> HexagonalWorldToTileY(worldY, snapToFloor, camera, layer)
Focus
Focus

Description:

Converts from world Y coordinates (pixels) to hexagonal tile Y coordinates (tile units), factoring in the layers position, scale and scroll.

Parameters:

name type description
worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in tile units.

Type:
  • number
Examples:
Focus
Focus
<static> IsInLayerBounds(tileX, tileY, layer)
Focus
Focus

Description:

Checks if the given tile coordinates are within the bounds of the layer.

Parameters:

name type description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

true if the tile coordinates are within the bounds of the layer, otherwise false.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
<static> IsometricCullTiles(layer, camera, [outputArray], [renderOrder])
Focus
Focus

Description:

Returns the tiles in the given layer that are within the cameras viewport. This is used internally.

Parameters:

name type arguments description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

outputArray array <optional>

An optional array to store the Tile objects within.

renderOrder number <optional>

The rendering order constant.

Returns:
Description:

An array of Tile objects.

Type:
Examples:
Since: 3.50.0
Focus
Focus
<static> IsometricTileToWorldXY(tileX, tileY, point, camera, layer)
Focus
Focus

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 description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in world coordinates.

Examples:
Focus
Focus
<static> IsometricWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Focus
Focus

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 description
worldX number

The x coordinate to be converted, in pixels, not tiles.

worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in tile units.

Examples:
Focus
Focus
<static> PutTileAt(tile, tileX, tileY, recalculateFaces, layer)
Focus
Focus

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 description
tile number | Phaser.Tilemaps.Tile

The index of this tile to set or a Tile object.

tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

recalculateFaces boolean

true if the faces data should be recalculated.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Tile object that was created or added to this map.

Examples:
Since: 3.0.0
Focus
Focus
<static> PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer)
Focus
Focus

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 information will be recalculated at the specified location.

Parameters:

name type description
tile number | Phaser.Tilemaps.Tile

The index of this tile to set or a Tile object.

worldX number

The x coordinate, in pixels.

worldY number

The y coordinate, in pixels.

recalculateFaces boolean

true if the faces data should be recalculated.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Tile object that was created or added to this map.

Examples:
Since: 3.0.0
Focus
Focus
<static> PutTilesAt(tile, tileX, tileY, recalculateFaces, layer)
Focus
Focus

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 description
tile Array.<number> | Array.<Array.<number>> | Array.<Phaser.Tilemaps.Tile> | Array.<Array.<Phaser.Tilemaps.Tile>>

A row (array) or grid (2D array) of Tiles or tile indexes to place.

tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

recalculateFaces boolean

true if the faces data should be recalculated.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> Randomize(tileX, tileY, width, height, indexes, layer)
Focus
Focus

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 description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

indexes Array.<number>

An array of indexes to randomly draw from during randomization.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer)
Focus
Focus

Description:

Removes the tile at the given tile coordinates in the specified layer and updates the layer's collision information.

Parameters:

name type description
tileX number

The x coordinate.

tileY number

The y coordinate.

replaceWithNull boolean

If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1.

recalculateFaces boolean

true if the faces data should be recalculated.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Tile object that was removed.

Examples:
Since: 3.0.0
Focus
Focus
<static> RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer)
Focus
Focus

Description:

Removes the tile at the given world coordinates in the specified layer and updates the layer's collision information.

Parameters:

name type description
worldX number

The x coordinate, in pixels.

worldY number

The y coordinate, in pixels.

replaceWithNull boolean

If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1.

recalculateFaces boolean

true if the faces data should be recalculated.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Tile object that was removed.

Examples:
Focus
Focus
<static> RenderDebug(graphics, styleConfig, layer)
Focus
Focus

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 description
graphics Phaser.GameObjects.Graphics

The target Graphics object to draw upon.

styleConfig Phaser.Types.Tilemaps.DebugStyleOptions

An object specifying the colors to use for the debug drawing.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, layer)
Focus
Focus

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 description
findIndex number

The index of the tile to search for.

newIndex number

The index of the tile to replace it with.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> RunCull(layer, bounds, renderOrder, outputArray)
Focus
Focus

Description:

Returns the tiles in the given layer that are within the cameras viewport. This is used internally.

Parameters:

name type description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

bounds object

An object containing the left, right, top and bottom bounds.

renderOrder number

The rendering order constant.

outputArray array

The array to store the Tile objects within.

Returns:
Description:

An array of Tile objects.

Type:
Examples:
Since: 3.50.0
Focus
Focus
<static> SetCollision(indexes, collides, recalculateFaces, layer, [updateLayer])
Focus
Focus

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).

Parameters:

name type arguments Default description
indexes number | array

Either a single tile index, or an array of tile indexes.

collides boolean

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean

Whether or not to recalculate the tile faces after the update.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

updateLayer boolean <optional> true

If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost.

Examples:
Since: 3.0.0
Focus
Focus
<static> SetCollisionBetween(start, stop, collides, recalculateFaces, layer, [updateLayer])
Focus
Focus

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 arguments Default description
start number

The first index of the tile to be set for collision.

stop number

The last index of the tile to be set for collision.

collides boolean

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean

Whether or not to recalculate the tile faces after the update.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

updateLayer boolean <optional> true

If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost.

Examples:
Focus
Focus
<static> SetCollisionByExclusion(indexes, collides, recalculateFaces, layer)
Focus
Focus

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 description
indexes Array.<number>

An array of the tile indexes to not be counted for collision.

collides boolean

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean

Whether or not to recalculate the tile faces after the update.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> SetCollisionByProperty(properties, collides, recalculateFaces, layer)
Focus
Focus

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 description
properties object

An object with tile properties and corresponding values that should be checked.

collides boolean

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean

Whether or not to recalculate the tile faces after the update.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> SetCollisionFromCollisionGroup(collides, recalculateFaces, layer)
Focus
Focus

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 description
collides boolean

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean

Whether or not to recalculate the tile faces after the update.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> SetLayerCollisionIndex(tileIndex, collides, layer)
Focus
Focus

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 description
tileIndex number

The tile index to set the collision boolean for.

collides boolean

Should the tile index collide or not?

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> SetTileCollision(tile, [collides])
Focus
Focus

Description:

Internally used method to set the colliding state of a tile. This does not recalculate interesting faces.

Parameters:

name type arguments Default description
tile Phaser.Tilemaps.Tile

The Tile to set the collision on.

collides boolean <optional> true

Should the tile index collide or not?

Examples:
Since: 3.0.0
Focus
Focus
<static> SetTileIndexCallback(indexes, callback, callbackContext, layer)
Focus
Focus

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 description
indexes number | array

Either a single tile index, or an array of tile indexes to have a collision callback set for.

callback function

The callback that will be invoked when the tile is collided with.

callbackContext object

The context under which the callback is called.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> SetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, layer)
Focus
Focus

Description:

Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.

Parameters:

name type description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

callback function

The callback that will be invoked when the tile is collided with.

callbackContext object

The context under which the callback is called.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Focus
Focus
<static> Shuffle(tileX, tileY, width, height, layer)
Focus
Focus

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 description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> StaggeredCullBounds(layer, camera)
Focus
Focus

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 description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

Returns:
Description:

An object containing the left, right, top and bottom bounds.

Type:
  • object
Examples:
Since: 3.50.0
Focus
Focus
<static> StaggeredCullTiles(layer, camera, [outputArray], [renderOrder])
Focus
Focus

Description:

Returns the tiles in the given layer that are within the cameras viewport. This is used internally.

Parameters:

name type arguments description
layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

camera Phaser.Cameras.Scene2D.Camera

The Camera to run the cull check against.

outputArray array <optional>

An optional array to store the Tile objects within.

renderOrder number <optional>

The rendering order constant.

Returns:
Description:

An array of Tile objects.

Type:
Examples:
Since: 3.50.0
Focus
Focus
<static> StaggeredTileToWorldXY(tileX, tileY, point, camera, layer)
Focus
Focus

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 description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in world coordinates.

Examples:
Focus
Focus
<static> StaggeredTileToWorldY(tileY, camera, layer)
Focus
Focus

Description:

Converts from staggered tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the layers position, scale and scroll.

Parameters:

name type description
tileY number

The y coordinate, in tiles, not pixels.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in world coordinates.

Type:
  • number
Examples:
Focus
Focus
<static> StaggeredWorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Focus
Focus

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 description
worldX number

The x coordinate to be converted, in pixels, not tiles.

worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in tile units.

Examples:
Focus
Focus
<static> StaggeredWorldToTileY(worldY, snapToFloor, camera, layer)
Focus
Focus

Description:

Converts from world Y coordinates (pixels) to staggered tile Y coordinates (tile units), factoring in the layers position, scale and scroll.

Parameters:

name type description
worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in tile units.

Type:
  • number
Examples:
Focus
Focus
<static> SwapByIndex(tileA, tileB, tileX, tileY, width, height, layer)
Focus
Focus

Description:

Scans the given rectangular area (given in tile coordinates) for tiles with an index matching indexA and swaps then with indexB. This only modifies the index and does not change collision information.

Parameters:

name type description
tileA number

First tile index.

tileB number

Second tile index.

tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> TileToWorldX(tileX, camera, layer)
Focus
Focus

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 description
tileX number

The x coordinate, in tiles, not pixels.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> TileToWorldXY(tileX, tileY, point, camera, layer)
Focus
Focus

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 description
tileX number

The x coordinate, in tiles, not pixels.

tileY number

The y coordinate, in tiles, not pixels.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in world coordinates.

Examples:
Since: 3.0.0
Focus
Focus
<static> TileToWorldY(tileY, camera, layer)
Focus
Focus

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 description
tileY number

The y coordinate, in tiles, not pixels.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in world coordinates.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> WeightedRandomize(tileX, tileY, width, height, weightedIndexes, layer)
Focus
Focus

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 27 would be 0.5 / 8 ]

The probability of any index being choose is (the index's weight) / (sum of all weights). This method only modifies tile indexes and does not change collision information.

Parameters:

name type description
tileX number

The left most tile index (in tile coordinates) to use as the origin of the area.

tileY number

The top most tile index (in tile coordinates) to use as the origin of the area.

width number

How many tiles wide from the tileX index the area will be.

height number

How many tiles tall from the tileY index the area will be.

weightedIndexes Array.<object>

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

The Tilemap Layer to act upon.

Examples:
Since: 3.0.0
Focus
Focus
<static> WorldToTileX(worldX, snapToFloor, camera, layer)
Focus
Focus

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 description
worldX number

The x coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The X location in tile units.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
<static> WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer)
Focus
Focus

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 description
worldX number

The x coordinate to be converted, in pixels, not tiles.

worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

point Phaser.Math.Vector2

A Vector2 to store the coordinates in. If not given a new Vector2 is created.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The XY location in tile units.

Examples:
Since: 3.0.0
Focus
Focus
<static> WorldToTileY(worldY, snapToFloor, camera, layer)
Focus
Focus

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 description
worldY number

The y coordinate to be converted, in pixels, not tiles.

snapToFloor boolean

Whether or not to round the tile coordinate down to the nearest integer.

camera Phaser.Cameras.Scene2D.Camera

The Camera to use when calculating the tile index from the world values.

layer Phaser.Tilemaps.LayerData

The Tilemap Layer to act upon.

Returns:
Description:

The Y location in tile units.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus