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 currentLayer
number The current layer.
-
debugMap
-
- Source:
Properties:
Name Type Description debugMap
array Map data used for debug values only.
-
dirty
-
- Source:
Properties:
Name Type Description dirty
boolean Internal rendering related flag.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
layers
-
- Source:
Properties:
Name Type Description layers
array 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 x
number X position of the top left of the area to copy (given in tiles, not pixels)
y
number Y position of the top left of the area to copy (given in tiles, not pixels)
width
number The width of the area to copy (given in tiles, not pixels)
height
number The height of the area to copy (given in tiles, not pixels)
layer
number <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 name
string The name of the map (mostly used for debugging)
width
number The width of the map in tiles.
height
number 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 index
number Index of tiles you want to fill with.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
layer
number <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 callback
number The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
context
number The context under which the callback should be run.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
layer
number <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 x
number X position to get the tile from (given in tile units, not pixels)
y
number Y position to get the tile from (given in tile units, not pixels)
layer
number <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 x
number X position to get the tile from (given in pixels)
y
number Y position to get the tile from (given in pixels)
layer
number <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 x
number X position of the top left of the area to paste to (given in tiles, not pixels)
y
number Y position of the top left of the area to paste to (given in tiles, not pixels)
tileblock
array The block of tiles to paste.
layer
number 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 index
number The index of this tile to set.
x
number X position to place the tile (given in tile units, not pixels)
y
number Y position to place the tile (given in tile units, not pixels)
layer
number <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 index
number The index of the tile to put into the layer.
x
number X position to insert the tile (given in pixels)
y
number Y position to insert the tile (given in pixels)
tileWidth
number The width of the tile in pixels.
tileHeight
number The height of the tile in pixels.
layer
number <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 tileA
number First tile index.
tileB
number Second tile index.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
layer
number <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 tileA
number First tile index.
tileB
number Second tile index.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
layer
number <optional>
The Tilemap Layer to operate on.
- Source:
-
setLayer(layer)
-
Sets the current layer to the given index.
Parameters:
Name Type Description layer
number 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 tileA
number First tile index.
tileB
number Second tile index.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
layer
number <optional>
The Tilemap Layer to operate on.
- Source:
-
swapHandler(value, index)
-
Internal function that handles the swapping of tiles.
Parameters:
Name Type Description value
number index
number - Source:
-
swapTile(tileA, tileB, x, y, width, height)
-
Swap tiles with 2 kinds of indexes.
Parameters:
Name Type Description tileA
number First tile index.
tileB
number Second tile index.
x
number X position of the top left of the area to operate one, given in tiles, not pixels.
y
number Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number The width in tiles of the area to operate on.
height
number The height in tiles of the area to operate on.
- Source: