new Tilemap(game, key)
A Tile Map object. A Tile map consists of a set of tile data and tile sets. It is rendered to the display using a TilemapLayer. A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
game |
Phaser.Game | Game reference to the currently running game. |
|
key |
string |
<optional> |
The key of the tilemap data as stored in the Cache. |
- Source:
Members
-
<static, constant> CSV :number
-
Type:
- number
- Source:
-
<static, constant> TILED_JSON :number
-
Type:
- number
- Source:
-
currentLayer
-
- Source:
Properties:
Name Type Description currentLayernumber The current layer.
-
debugMap
-
- Source:
Properties:
Name Type Description debugMaparray Map data used for debug values only.
-
dirty
-
- Source:
Properties:
Name Type Description dirtyboolean Internal rendering related flag.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game A reference to the currently running Game.
-
layers
-
- Source:
Properties:
Name Type Description layersarray An array of Tilemap layers.
Methods
-
calculateIndexes()
-
Internal function that calculates the tile indexes for the map data.
- Source:
-
copy(x, y, width, height, layer) → {array}
-
Copies all of the tiles in the given rectangular block into the tilemap data buffer.
Parameters:
Name Type Argument Description xnumber X position of the top left of the area to copy (given in tiles, not pixels)
ynumber Y position of the top left of the area to copy (given in tiles, not pixels)
widthnumber The width of the area to copy (given in tiles, not pixels)
heightnumber The height of the area to copy (given in tiles, not pixels)
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
Returns:
An array of the tiles that were copied.
- Type
- array
-
create(name, width, height)
-
Creates an empty map of the given dimensions.
Parameters:
Name Type Description namestring The name of the map (mostly used for debugging)
widthnumber The width of the map in tiles.
heightnumber The height of the map in tiles.
- Source:
-
destroy()
-
Removes all layers from this tile map and nulls the game reference.
- Source:
-
dump()
-
Dumps the tilemap data out to the console.
- Source:
-
fill(index, x, y, width, height, layer)
-
Fill a block with a specific tile index.
Parameters:
Name Type Argument Description indexnumber Index of tiles you want to fill with.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
forEach(callback, context, x, y, width, height, layer)
-
For each tile in the given area (defined by x/y and width/height) run the given callback.
Parameters:
Name Type Argument Description callbacknumber The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
contextnumber The context under which the callback should be run.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
getTile(x, y, layer) → {number}
-
Gets a tile from the Tilemap Layer. The coordinates are given in tile values.
Parameters:
Name Type Argument Description xnumber X position to get the tile from (given in tile units, not pixels)
ynumber Y position to get the tile from (given in tile units, not pixels)
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
Returns:
The index of the tile at the given coordinates.
- Type
- number
-
getTileWorldXY(x, y, layer) → {number}
-
Gets a tile from the Tilemap layer. The coordinates are given in pixel values.
Parameters:
Name Type Argument Description xnumber X position to get the tile from (given in pixels)
ynumber Y position to get the tile from (given in pixels)
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
Returns:
The index of the tile at the given coordinates.
- Type
- number
-
paste(x, y, tileblock, layer)
-
Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy.
Parameters:
Name Type Description xnumber X position of the top left of the area to paste to (given in tiles, not pixels)
ynumber Y position of the top left of the area to paste to (given in tiles, not pixels)
tileblockarray The block of tiles to paste.
layernumber The Tilemap Layer to operate on.
- Source:
-
putTile(index, x, y, layer)
-
Puts a tile of the given index value at the coordinate specified.
Parameters:
Name Type Argument Description indexnumber The index of this tile to set.
xnumber X position to place the tile (given in tile units, not pixels)
ynumber Y position to place the tile (given in tile units, not pixels)
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
putTileWorldXY(index, x, y, tileWidth, tileHeight, layer)
-
Puts a tile into the Tilemap layer. The coordinates are given in pixel values.
Parameters:
Name Type Argument Description indexnumber The index of the tile to put into the layer.
xnumber X position to insert the tile (given in pixels)
ynumber Y position to insert the tile (given in pixels)
tileWidthnumber The width of the tile in pixels.
tileHeightnumber The height of the tile in pixels.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
random(tileA, tileB, x, y, width, height, layer)
-
Randomises a set of tiles in a given area.
Parameters:
Name Type Argument Description tileAnumber First tile index.
tileBnumber Second tile index.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
removeAllLayers()
-
Removes all layers from this tile map.
- Source:
-
replace(tileA, tileB, x, y, width, height, layer)
-
Replaces one type of tile with another in the given area (defined by x/y and width/height).
Parameters:
Name Type Argument Description tileAnumber First tile index.
tileBnumber Second tile index.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
setLayer(layer)
-
Sets the current layer to the given index.
Parameters:
Name Type Description layernumber Sets the current layer to the given index.
- Source:
-
shuffle(tileA, tileB, x, y, width, height, layer)
-
Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
Parameters:
Name Type Argument Description tileAnumber First tile index.
tileBnumber Second tile index.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
layernumber <optional>
The Tilemap Layer to operate on.
- Source:
-
swapHandler(value, index)
-
Internal function that handles the swapping of tiles.
Parameters:
Name Type Description valuenumber indexnumber - Source:
-
swapTile(tileA, tileB, x, y, width, height)
-
Swap tiles with 2 kinds of indexes.
Parameters:
Name Type Description tileAnumber First tile index.
tileBnumber Second tile index.
xnumber X position of the top left of the area to operate one, given in tiles, not pixels.
ynumber Y position of the top left of the area to operate one, given in tiles, not pixels.
widthnumber The width in tiles of the area to operate on.
heightnumber The height in tiles of the area to operate on.
- Source: