Class: Tilemap

Phaser. Tilemap

Phaser.Tilemap

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

Properties:
Name Type Description
currentLayer number

The current layer.

Source:

debugMap

Properties:
Name Type Description
debugMap array

Map data used for debug values only.

Source:

game

Properties:
Name Type Description
game Phaser.Game

A reference to the currently running Game.

Source:

images

Properties:
Name Type Description
images array

An array of Tiled Image Layers.

Source:

key

Properties:
Name Type Description
key string

The key of this map data in the Phaser.Cache.

Source:

layers

Properties:
Name Type Description
layers array

An array of Tilemap layer data.

Source:

objects

Properties:
Name Type Description
objects array

An array of Tiled Object Layers.

Source:

tiles

Properties:
Name Type Description
tiles array

The super array of Tiles.

Source:

tilesets

Properties:
Name Type Description
tilesets array

An array of Tilesets.

Source:

Methods

addTilesetImage(tileset, key)

Adds an image to the map to be used as a tileset. A single map may use multiple tilesets. Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled editor.

Parameters:
Name Type Argument Description
tileset string

The name of the tileset as specified in the map data.

key string <optional>

The key of the Phaser.Cache image used for this tileset. If not specified it will look for an image with a key matching the tileset parameter.

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 | string | Phaser.TilemapLayer <optional>

The layer to copy the tiles from.

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)

Fills the given area with the specified tile.

Parameters:
Name Type Argument Description
index number

The index of the tile that the area will be filled 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 | string | Phaser.TilemapLayer <optional>

The 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 | string | Phaser.TilemapLayer <optional>

The layer to operate on.

Source:

getTile(x, y, layer) → {Phaser.Tile}

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 | string | Phaser.TilemapLayer <optional>

The layer to get the tile from.

Source:
Returns:

The tile at the given coordinates.

Type
Phaser.Tile

getTileWorldXY(x, y, layer) → {Phaser.Tile}

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 | string | Phaser.TilemapLayer <optional>

The layer to get the tile from.

Source:
Returns:

The tile at the given coordinates.

Type
Phaser.Tile

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 Argument 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 | string | Phaser.TilemapLayer <optional>

The layer to paste the tiles into.

Source:

putTile(tile, x, y, layer)

Puts a tile of the given index value at the coordinate specified.

Parameters:
Name Type Argument Description
tile Phaser.Tile | number

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

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 | string | Phaser.TilemapLayer <optional>

The layer to modify.

Source:

putTileWorldXY(tile, x, y, tileWidth, tileHeight, layer)

Puts a tile into the Tilemap layer. The coordinates are given in pixel values.

Parameters:
Name Type Argument Description
tile Phaser.Tile | number

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

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 | string | Phaser.TilemapLayer <optional>

The layer to modify.

Source:

random(x, y, width, height, layer)

Randomises a set of tiles in a given area.

Parameters:
Name Type Argument Description
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 | string | Phaser.TilemapLayer <optional>

The layer to operate on.

Source:

removeAllLayers()

Removes all layers from this tile map.

Source:

replace(source, dest, x, y, width, height, layer)

Scans the given area for tiles with an index matching source and updates their index to match dest.

Parameters:
Name Type Argument Description
source number

The tile index value to scan for.

dest number

The tile index value to replace found tiles 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 | string | Phaser.TilemapLayer <optional>

The layer to operate on.

Source:

setLayer(layer)

Sets the current layer to the given index.

Parameters:
Name Type Description
layer number | string | Phaser.TilemapLayer

The layer to set as current.

Source:

shuffle(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
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 | string | Phaser.TilemapLayer <optional>

The layer to operate on.

Source:

swapTile(tileA, tileB, x, y, width, height, layer)

Scans the given area for tiles with an index matching tileA and swaps them with tileB.

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 | string | Phaser.TilemapLayer <optional>

The layer to operate on.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Wed Feb 05 2014 06:28:35 GMT-0000 (GMT) using the DocStrap template.