new Tilemap(game [, key] [, tileWidth] [, tileHeight] [, width] [, height])
Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use Tilemap.create
or pass the map and tile dimensions here.
Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself.
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 | Default | 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. If you're creating a blank map either leave this parameter out or pass |
|
tileWidth |
number |
<optional> |
32 | The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. |
tileHeight |
number |
<optional> |
32 | The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. |
width |
number |
<optional> |
10 | The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. |
height |
number |
<optional> |
10 | The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. |
- Source:
- src/tilemap/Tilemap.js line 28
Members
-
<static, constant> CSV : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 180
-
<static, constant> EAST : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 198
-
<static, constant> NORTH : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 192
-
<static, constant> SOUTH : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 204
-
<static, constant> TILED_JSON : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 186
-
<static, constant> WEST : number
-
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 210
-
collideIndexes : array
-
An array of tile indexes that collide.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 130
-
collision : array
-
An array of collision data (polylines, etc).
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 135
-
currentLayer : number
-
The current layer.
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 150
-
debugMap : array
-
Map data used for debug values only.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 155
-
enableDebug : boolean
-
If set then console.log is used to dump out useful layer creation debug data.
Type:
- boolean
- Source:
- src/tilemap/Tilemap.js line 145
-
format : number
-
The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 75
-
game : Phaser.Game
-
A reference to the currently running Game.
Type:
- Source:
- src/tilemap/Tilemap.js line 33
-
height : number
-
The height of the map (in tiles).
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 55
-
heightInPixels : number
-
The height of the map in pixels based on height * tileHeight.
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 95
-
imagecollections : array
-
An array of Image Collections.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 110
-
images : array
-
An array of Tiled Image Layers.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 140
-
key : string
-
The key of this map data in the Phaser.Cache.
Type:
- string
- Source:
- src/tilemap/Tilemap.js line 38
-
layer : number | string | Phaser.TilemapLayer
-
The current layer object.
Type:
- number | string | Phaser.TilemapLayer
- Source:
- src/tilemap/Tilemap.js line 2056
-
layers : array
-
An array of Tilemap layer data.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 100
-
objects : object
-
Tiled Object Layers, by layer name.
Type:
- object
- Source:
- src/tilemap/Tilemap.js line 120
-
objectsMap : object
-
Tiled objects indexed by
id
.Type:
- object
- Source:
- src/tilemap/Tilemap.js line 125
-
orientation : string
-
The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
Type:
- string
- Source:
- src/tilemap/Tilemap.js line 70
-
properties : object
-
Map specific properties as specified in Tiled.
Type:
- object
- Source:
- src/tilemap/Tilemap.js line 85
-
tileHeight : number
-
The base height of the tiles in the map (in pixels).
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 65
-
tiles : array
-
The super array of Tiles.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 115
-
tilesets : array
-
An array of Tilesets.
Type:
- array
- Source:
- src/tilemap/Tilemap.js line 105
-
tileWidth : number
-
The base width of the tiles in the map (in pixels).
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 60
-
version : number
-
The version of the map data (as specified in Tiled, usually 1).
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 80
-
width : number
-
The width of the map (in tiles).
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 50
-
widthInPixels : number
-
The width of the map in pixels based on width * tileWidth.
Type:
- number
- Source:
- src/tilemap/Tilemap.js line 90
Methods
-
addTilesetImage(tileset [, key] [, tileWidth] [, tileHeight] [, tileMargin] [, tileSpacing] [, gid])
-
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 Default Description tileset
string The name of the tileset as specified in the map data.
key
string | Phaser.BitmapData <optional>
The key of the Phaser.Cache image used for this tileset. If
undefined
ornull
it will look for an image with a key matching the tileset parameter. You can also pass in a BitmapData which can be used instead of an Image.tileWidth
number <optional>
32 The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value, if that isn't set then 32.
tileHeight
number <optional>
32 The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value, if that isn't set then 32.
tileMargin
number <optional>
0 The width of the tiles in the Tileset Image.
tileSpacing
number <optional>
0 The height of the tiles in the Tileset Image.
gid
number <optional>
0 If adding multiple tilesets to a blank/dynamic map, specify the starting GID the set will use here.
- Source:
- src/tilemap/Tilemap.js line 255
Returns:
Returns the Tileset object that was created or updated, or null if it failed.
- Type
- Phaser.Tileset
-
<protected> calculateFaces(layer)
-
Internal function.
Parameters:
Name Type Description layer
number The index of the TilemapLayer to operate on.
- Source:
- src/tilemap/Tilemap.js line 1168
-
copy( [x] [, y] [, width] [, height] [, layer])
-
Copies all of the tiles in the given rectangular block into the tilemap data buffer.
Parameters:
Name Type Argument Default Description x
integer <optional>
0 X position of the top left of the area to copy (given in tiles, not pixels)
y
integer <optional>
0 Y position of the top left of the area to copy (given in tiles, not pixels)
width
integer <optional>
The width of the area to copy (given in tiles, not pixels)
height
integer <optional>
The height of the area to copy (given in tiles, not pixels)
layer
integer | string | Phaser.TilemapLayer <optional>
The layer to copy the tiles from.
- Source:
- src/tilemap/Tilemap.js line 1659
Returns:
An array of the tiles that were copied.
- Type
- array
-
create(name, width, height, tileWidth, tileHeight [, group])
-
Creates an empty map of the given dimensions and one blank layer. If layers already exist they are erased.
Parameters:
Name Type Argument Description name
string The name of the default layer of the map.
width
number The width of the map in tiles.
height
number The height of the map in tiles.
tileWidth
number The width of the tiles the map uses for calculations.
tileHeight
number The height of the tiles the map uses for calculations.
group
Phaser.Group <optional>
Optional Group to add the layer to. If not specified it will be added to the World group.
- Source:
- src/tilemap/Tilemap.js line 214
Returns:
The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly.
- Type
- Phaser.TilemapLayer
-
createBlankLayer(name, width, height, tileWidth, tileHeight [, group])
-
Creates a new and empty layer on this Tilemap. By default TilemapLayers are fixed to the camera.
Parameters:
Name Type Argument Description name
string The name of this layer. Must be unique within the map.
width
number The width of the layer in tiles.
height
number The height of the layer in tiles.
tileWidth
number The width of the tiles the layer uses for calculations.
tileHeight
number The height of the tiles the layer uses for calculations.
group
Phaser.Group <optional>
Optional Group to add the layer to. If not specified it will be added to the World group.
- Source:
- src/tilemap/Tilemap.js line 667
Returns:
The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly.
- Type
- Phaser.TilemapLayer
-
createFromObjects(layer, search, key [, frame] [, exists] [, autoCull] [, group] [, CustomClass] [, adjustY] [, adjustSize])
-
Creates a Sprite for every object matching the
search
argument.- When
search
is a number, it matches the object's tile ID (gid
). - When
search
is a string, it matches the object'sname
. - When
search
is an array like['type', 'enemy']
it matches that property name and value on the object. - When
search
isnull
, it matches every object.
You can optionally specify the group that the Sprite will be created in. If
undefined
is given it will be created in the World. Ifnull
is given it won't be added to any group.All properties from the object are copied to the Sprite, so you can use this as an easy way to configure Sprite properties from within the map editor. For example giving an object a property of
alpha: 0.5
in the map editor will duplicate that when the Sprite is created. You could also give it a value like:body.velocity.x: 100
to set it moving automatically.Parameters:
Name Type Argument Default Description layer
string The name of the Object Group (Object Layer) to create Sprites from.
search
number | string | array | null The search value (see above).
key
string The Game.cache key of the image that this Sprite will use.
frame
number | string <optional>
If the Sprite image contains multiple frames you can specify which one to use here.
exists
boolean <optional>
true The default exists state of the Sprite.
autoCull
boolean <optional>
false The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.
group
Phaser.Group | null <optional>
this.game.world Group to add the Sprite to, or
null
for no group. Ifundefined
it will be added to the World group.CustomClass
object <optional>
Phaser.Sprite If you wish to create your own class, rather than Phaser.Sprite, pass the class here. Your class must extend Phaser.Sprite and have the same constructor parameters.
adjustY
boolean <optional>
true By default the Tiled map editor uses a bottom-left coordinate system. Phaser uses top-left. So most objects will appear too low down. This parameter moves them up by their height.
adjustSize
boolean <optional>
true By default the width and height of the objects are transferred to the sprite. This parameter controls that behavior.
- Source:
- src/tilemap/Tilemap.js line 377
Returns:
- The created Sprites.
- Type
- Array.<Phaser.Sprite>
- When
-
createFromTiles(tiles, replacements, key [, layer] [, group] [, properties])
-
Creates a Sprite for every object matching the given tile indexes in the map data. You can specify the group that the Sprite will be created in. If none is given it will be created in the World. You can optional specify if the tile will be replaced with another after the Sprite is 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 Argument Default Description tiles
integer | Array The tile index, or array of indexes, to create Sprites from.
replacements
integer | Array The tile index, or array of indexes, to change a converted tile to. Set to -1 to remove the tile. Set to
null
to make no change (leave the tile as is).key
string The Game.cache key of the image that this Sprite will use.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on.
group
Phaser.Group <optional>
Phaser.World Group to add the Sprite to. If not specified it will be added to the World group.
properties
object <optional>
An object that contains the default properties for your newly created Sprite. This object will be iterated and any matching Sprite property will be set.
- Source:
- src/tilemap/Tilemap.js line 502
Returns:
The number of Sprites that were created.
- Type
- integer
-
createLayer(layer [, width] [, height] [, group])
-
Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera. The
layer
parameter is important. If you've created your map in Tiled then you can get this by looking in Tiled and looking at the Layer name. Or you can open the JSON file it exports and look at the layers[].name value. Either way it must match. If you wish to create a blank layer to put your own tiles on then see Tilemap.createBlankLayer.Parameters:
Name Type Argument Description layer
number | string The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents.
width
number <optional>
The rendered width of the layer, should never be wider than Game.width. If not given it will be set to Game.width.
height
number <optional>
The rendered height of the layer, should never be wider than Game.height. If not given it will be set to Game.height.
group
Phaser.Group <optional>
Optional Group to add the object to. If not specified it will be added to the World group.
- Source:
- src/tilemap/Tilemap.js line 594
Returns:
The TilemapLayer object. This is an extension of Phaser.Sprite and can be moved around the display list accordingly.
- Type
- Phaser.TilemapLayer
-
destroy()
-
Removes all layer data from this tile map and nulls the game reference. Note: You are responsible for destroying any TilemapLayer objects you generated yourself, as Tilemap doesn't keep a reference to them.
- Source:
- src/tilemap/Tilemap.js line 2039
-
dump()
-
Dumps the tilemap data out to the console.
- Source:
- src/tilemap/Tilemap.js line 1999
-
fill(index, x, y, width, height [, layer])
-
Fills the given area with the specified tile. Only the tile indexes are modified.
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:
- src/tilemap/Tilemap.js line 1957
-
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:
- src/tilemap/Tilemap.js line 1807
-
getImageIndex(name)
-
Gets the image index based on its name.
Parameters:
Name Type Description name
string The name of the image to get.
- Source:
- src/tilemap/Tilemap.js line 839
Returns:
The index of the image in this tilemap, or null if not found.
- Type
- number
-
<protected> getIndex(location, name)
-
Gets the layer index based on the layers name.
Parameters:
Name Type Description location
array The local array to search.
name
string The name of the array element to get.
- Source:
- src/tilemap/Tilemap.js line 748
Returns:
The index of the element in the array, or null if not found.
- Type
- number
-
<protected> getLayer(layer)
-
Gets the TilemapLayer index as used in the setCollision calls.
Parameters:
Name Type Description layer
number | string | Phaser.TilemapLayer The layer to operate on. If not given will default to this.currentLayer.
- Source:
- src/tilemap/Tilemap.js line 1107
Returns:
The TilemapLayer index.
- Type
- number
-
getLayerIndex(name)
-
Gets the layer index based on its name.
Parameters:
Name Type Description name
string The name of the layer to get.
- Source:
- src/tilemap/Tilemap.js line 770
Returns:
The index of the layer in this tilemap, or null if not found.
- Type
- number
-
getObject(id)
-
Gets the object with the given
id
, from any Object Layer.Parameters:
Name Type Description id
number The
id
of the object.- Source:
- src/tilemap/Tilemap.js line 789
Returns:
The object, or null if not found.
- Type
- TilemapObject
-
getObjects(layer, propName, propValue [, output])
-
Gets objects matching the given property name and value from an Object Layer.
Parameters:
Name Type Argument Description layer
string The name of the Object Layer.
propName
string The name of the object property to match.
propValue
any The property value to match.
output
array <optional>
An array to append matching objects to.
- Source:
- src/tilemap/Tilemap.js line 804
Returns:
- The matching objects.
- Type
- Array.<TilemapObject>
-
getTile(x, y [, layer] [, nonNull])
-
Gets a tile from the Tilemap Layer. The coordinates are given in tile values.
Parameters:
Name Type Argument Default 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.
nonNull
boolean <optional>
false If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
- Source:
- src/tilemap/Tilemap.js line 1594
Returns:
The tile at the given coordinates or null if no tile was found or the coordinates were invalid.
- Type
- Phaser.Tile
-
getTileAbove(layer, x, y)
-
Gets the tile above the tile coordinates given. Mostly used as an internal function by calculateFaces.
Parameters:
Name Type Description layer
number The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
x
number The x coordinate to get the tile from. In tiles, not pixels.
y
number The y coordinate to get the tile from. In tiles, not pixels.
- Source:
- src/tilemap/Tilemap.js line 1237
-
getTileBelow(layer, x, y)
-
Gets the tile below the tile coordinates given. Mostly used as an internal function by calculateFaces.
Parameters:
Name Type Description layer
number The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
x
number The x coordinate to get the tile from. In tiles, not pixels.
y
number The y coordinate to get the tile from. In tiles, not pixels.
- Source:
- src/tilemap/Tilemap.js line 1256
-
getTileLeft(layer, x, y)
-
Gets the tile to the left of the tile coordinates given. Mostly used as an internal function by calculateFaces.
Parameters:
Name Type Description layer
number The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
x
number The x coordinate to get the tile from. In tiles, not pixels.
y
number The y coordinate to get the tile from. In tiles, not pixels.
- Source:
- src/tilemap/Tilemap.js line 1275
-
getTileRight(layer, x, y)
-
Gets the tile to the right of the tile coordinates given. Mostly used as an internal function by calculateFaces.
Parameters:
Name Type Description layer
number The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
x
number The x coordinate to get the tile from. In tiles, not pixels.
y
number The y coordinate to get the tile from. In tiles, not pixels.
- Source:
- src/tilemap/Tilemap.js line 1294
-
getTilesetIndex(name)
-
Gets the tileset index based on its name.
Parameters:
Name Type Description name
string The name of the tileset to get.
- Source:
- src/tilemap/Tilemap.js line 827
Returns:
The index of the tileset in this tilemap, or null if not found.
- Type
- number
-
getTileWorldXY(x, y [, tileWidth] [, tileHeight] [, layer] [, nonNull])
-
Gets a tile from the Tilemap layer. The coordinates are given in pixel values.
Parameters:
Name Type Argument Default 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)
tileWidth
number <optional>
The width of the tiles. If not given the map default is used.
tileHeight
number <optional>
The height of the tiles. If not given the map default is used.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to get the tile from.
nonNull
boolean <optional>
false If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
- Source:
- src/tilemap/Tilemap.js line 1634
Returns:
The tile at the given coordinates.
- Type
- Phaser.Tile
-
hasTile(x, y, layer)
-
Checks if there is a tile at the given location.
Parameters:
Name Type Description x
number X position to check if a tile exists at (given in tile units, not pixels)
y
number Y position to check if a tile exists at (given in tile units, not pixels)
layer
number | string | Phaser.TilemapLayer The layer to set as current.
- Source:
- src/tilemap/Tilemap.js line 1329
Returns:
True if there is a tile at the given location, otherwise false.
- Type
- boolean
-
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:
- src/tilemap/Tilemap.js line 1720
-
putTile(tile, x, y [, layer])
-
Puts a tile of the given index value at the coordinate specified. If you pass
null
as the tile it will pass your call over to Tilemap.removeTile instead.Parameters:
Name Type Argument Description tile
Phaser.Tile | number | null The index of this tile to set or a Phaser.Tile object. If a Tile object, all of its data will be copied. If null the tile is removed from the map.
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:
- src/tilemap/Tilemap.js line 1401
Returns:
The Tile object that was created or added to this map.
- Type
- Phaser.Tile
-
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:
- src/tilemap/Tilemap.js line 1471
Returns:
The Tile object that was created or added to this map.
- Type
- Phaser.Tile
-
random(x, y, width, height [, layer])
-
Randomises a set of tiles in a given area. Only the tile indexes are modified.
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:
- src/tilemap/Tilemap.js line 1870
-
removeAllLayers()
-
Removes all layers from this tile map.
- Source:
- src/tilemap/Tilemap.js line 1988
-
removeTile(x, y [, layer])
-
Removes the tile located at the given coordinates and updates the collision data.
Parameters:
Name Type Argument Description 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:
- src/tilemap/Tilemap.js line 1350
Returns:
The Tile object that was removed from this map.
- Type
- Phaser.Tile
-
removeTileWorldXY(x, y, tileWidth, tileHeight [, layer])
-
Removes the tile located at the given coordinates and updates the collision data. The coordinates are given in pixel values.
Parameters:
Name Type Argument Description 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:
- src/tilemap/Tilemap.js line 1380
Returns:
The Tile object that was removed from this map.
- Type
- Phaser.Tile
-
replace(source, dest [, x] [, y] [, width] [, height] [, layer])
-
Scans the given area for tiles with an index matching
source
and updates their index to matchdest
. Only the tile indexes are modified.Parameters:
Name Type Argument Default Description source
number The tile index value to scan for.
dest
number The tile index value to replace found tiles with.
x
number <optional>
0 X position of the top left of the area to operate one, given in tiles, not pixels.
y
number <optional>
0 Y position of the top left of the area to operate one, given in tiles, not pixels.
width
number <optional>
The width in tiles of the area to operate on.
height
number <optional>
The height in tiles of the area to operate on.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on.
- Source:
- src/tilemap/Tilemap.js line 1835
-
searchTileIndex(index [, skip] [, reverse] [, layer] [, all])
-
Searches the entire map layer for the first tile or all tiles matching the given index. When
all
is false (the default), it returns a Phaser.Tile object or null. Whenall
is true, it returns an array Phaser.Tile objects, or none (an empty array). 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 Argument Default Description index
number The tile index value to search for.
skip
number <optional>
0 The number of times to skip a matching tile before returning.
reverse
number <optional>
false If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to get the tile from.
all
number <optional>
false If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left.
- Source:
- src/tilemap/Tilemap.js line 1493
Returns:
A matching tile, or null (when
all
is false); or an array of zero or more tiles (whenall
is true).- Type
- Phaser.Tile | Array.<Phaser.Tile>
-
setCollision(indexes [, collides] [, layer] [, recalculate])
-
Sets collision on the given tile or tiles. 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).Collision-enabled tiles can be collided against Sprites using Phaser.Physics.Arcade#collide.
You can verify the collision faces by enabling Phaser.TilemapLayer#debug.
Parameters:
Name Type Argument Default Description indexes
number | array Either a single tile index, or an array of tile IDs to be checked for collision.
collides
boolean <optional>
true If true it will enable collision. If false it will clear collision.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on. If not given will default to this.currentLayer.
recalculate
boolean <optional>
true Recalculates the tile faces after the update.
- Source:
- src/tilemap/Tilemap.js line 932
-
setCollisionBetween(start, stop [, collides] [, layer] [, recalculate])
-
Sets collision on a range of tiles where the tile IDs increment sequentially. 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 Argument 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 <optional>
true If true it will enable collision. If false it will clear collision.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on. If not given will default to this.currentLayer.
recalculate
boolean <optional>
true Recalculates the tile faces after the update.
- Source:
- src/tilemap/Tilemap.js line 973
-
setCollisionByExclusion(indexes [, collides] [, layer] [, recalculate])
-
Sets collision on all tiles in the given layer, except for the IDs of those in the given array. The
collides
parameter controls if collision will be enabled (true) or disabled (false).Parameters:
Name Type Argument Default Description indexes
array An array of the tile IDs to not be counted for collision.
collides
boolean <optional>
true If true it will enable collision. If false it will clear collision.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on. If not given will default to this.currentLayer.
recalculate
boolean <optional>
true Recalculates the tile faces after the update.
- Source:
- src/tilemap/Tilemap.js line 1009
-
<protected> setCollisionByIndex(index [, collides] [, layer] [, recalculate])
-
Sets collision values on a tile in the set. You shouldn't usually call this method directly, instead use setCollision, setCollisionBetween or setCollisionByExclusion.
Parameters:
Name Type Argument Default Description index
number The index of the tile on the layer.
collides
boolean <optional>
true If true it will enable collision on the tile. If false it will clear collision values from the tile.
layer
number <optional>
The layer to operate on. If not given will default to this.currentLayer.
recalculate
boolean <optional>
true Recalculates the tile faces after the update.
- Source:
- src/tilemap/Tilemap.js line 1042
-
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:
- src/tilemap/Tilemap.js line 1313
-
setPreventRecalculate(value)
-
Turn off/on the recalculation of faces for tile or collision updates.
setPreventRecalculate(true)
puts recalculation on hold whilesetPreventRecalculate(false)
recalculates all the changed layers.Parameters:
Name Type Description value
boolean If true it will put the recalculation on hold.
- Source:
- src/tilemap/Tilemap.js line 1140
-
setTileIndexCallback(indexes, callback, callbackContext [, layer])
-
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.
Return
true
from the callback to continue separating the tile and colliding object, orfalse
to cancel the collision for the current tile (see Phaser.Physics.Arcade#separateTile).Parameters:
Name Type Argument 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 (via Phaser.Physics.Arcade#collide).
callbackContext
object The context under which the callback is called.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on. If not given will default to this.currentLayer.
- Source:
- src/tilemap/Tilemap.js line 851
-
setTileLocationCallback(x, y, width, height, callback, callbackContext [, layer])
-
Sets a global collision callback for the given map location within the layer. This will affect all tiles on this layer found in the given area. 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.
Return
true
from the callback to continue separating the tile and colliding object, orfalse
to cancel the collision for the current tile (see Phaser.Physics.Arcade#separateTile).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)
callback
function The callback that will be invoked when the tile is collided with (via Phaser.Physics.Arcade#collide).
callbackContext
object The context under which the callback is called.
layer
number | string | Phaser.TilemapLayer <optional>
The layer to operate on. If not given will default to this.currentLayer.
- Source:
- src/tilemap/Tilemap.js line 899
-
setTileSize(tileWidth, tileHeight)
-
Sets the base tile size for the map.
Parameters:
Name Type Description tileWidth
number The width of the tiles the map uses for calculations.
tileHeight
number The height of the tiles the map uses for calculations.
- Source:
- src/tilemap/Tilemap.js line 240
-
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! Only the tile indexes are modified.
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:
- src/tilemap/Tilemap.js line 1915
-
swap(tileA, tileB, x, y, width, height [, layer])
-
Scans the given area for tiles with an index matching tileA and swaps them with tileB. Only the tile indexes are modified.
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:
- src/tilemap/Tilemap.js line 1754