Class: Tileset

Phaser. Tileset

Phaser.Tileset

new Tileset(name, firstgid, width, height, margin, spacing, properties)

A Tile set is a combination of an image containing the tiles and collision data per tile. You should not normally instantiate this class directly.

Parameters:
Name Type Description
name string

The name of the tileset in the map data.

firstgid number

The Tiled firstgid value.

width number

Width of each tile in pixels.

height number

Height of each tile in pixels.

margin number

The amount of margin around the tilesheet.

spacing number

The amount of spacing between each tile in the sheet.

properties object

Tileset properties.

Source:

Members

columns

Properties:
Name Type Description
columns number

The number of columns in the tile sheet.

Source:

firstgid

Properties:
Name Type Description
firstgid number

The Tiled firstgid value.

Default Value:
  • firstgid
Source:

image

Properties:
Name Type Description
image object

The image used for rendering. This is a reference to the image stored in Phaser.Cache.

Source:

name

Properties:
Name Type Description
name string

The name of the Tileset.

Source:

properties

Properties:
Name Type Description
properties object

Tileset specific properties (typically defined in the Tiled editor).

Source:

rows

Properties:
Name Type Description
rows number

The number of rows in the tile sheet.

Source:

tileHeight

Properties:
Name Type Description
tileHeight number

The height of a tile in pixels.

Source:

tileMargin

Properties:
Name Type Description
tileMargin number

The margin around the tiles in the sheet.

Source:

tileSpacing

Properties:
Name Type Description
tileSpacing number

The margin around the tiles in the sheet.

Source:

tileWidth

Properties:
Name Type Description
tileWidth number

The width of a tile in pixels.

Source:

total

Properties:
Name Type Description
total number

The total number of tiles in the tilesheet.

Source:

Methods

<protected> calculateFaces(layer)

Internal function.

Parameters:
Name Type Description
layer number

The index of the TilemapLayer to operate on.

Source:

checkTileIndex(index) → {boolean}

Checks if the tile at the given index exists.

Parameters:
Name Type Description
index number

The index of the tile within the set.

Source:
Returns:

True if a tile exists at the given index otherwise false. checkTileIndex: function (index) {

    return (this.tiles[index]);

}
Type
boolean

createFromObjects(name, gid, key, frame, exists, autoCull, group)

Creates a Sprite for every object matching the given gid in the map data. You can optionally specify the group that the Sprite will be created in. If none is given it will be created in the World. All properties from the map data objectgroup are copied across 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 if 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
name string

The name of the Object Group to create Sprites from.

gid number

The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents.

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>
true

The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.

group Phaser.Group <optional>

Optional Group to add the Sprite to. If not specified it will be added to the World group.

Source:

createLayer(layer, width, height, group) → {Phaser.TilemapLayer}

Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera.

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:
Returns:

The TilemapLayer object. This is an extension of Phaser.Sprite and can be moved around the display list accordingly.

Type
Phaser.TilemapLayer

getImageIndex(name) → {number}

Gets the image index based on its name.

Parameters:
Name Type Description
name string

The name of the image to get.

Source:
Returns:

The index of the image in this tilemap, or null if not found.

Type
number

<protected> getIndex(location, name) → {number}

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:
Returns:

The index of the element in the array, or null if not found.

Type
number

<protected> getLayer(layer) → {number}

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:
Returns:

The TilemapLayer index.

Type
number

getLayerIndex(name) → {number}

Gets the layer index based on its name.

Parameters:
Name Type Description
name string

The name of the layer to get.

Source:
Returns:

The index of the layer in this tilemap, or null if not found.

Type
number

getObjectIndex(name) → {number}

Gets the object index based on its name.

Parameters:
Name Type Description
name string

The name of the object to get.

Source:
Returns:

The index of the object in this tilemap, or null if not found.

Type
number

getTile(index) → {object}

Gets a Tile from this set.

Parameters:
Name Type Description
index number

The index of the tile within the set.

Source:
Returns:

The tile object. getTile: function (index) {

    return this.tiles[index];

},
Type
object

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:

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:

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:

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:

getTilesetIndex(name) → {number}

Gets the tileset index based on its name.

Parameters:
Name Type Description
name string

The name of the tileset to get.

Source:
Returns:

The index of the tileset in this tilemap, or null if not found.

Type
number

getTileX(index) → {object}

Gets a Tile from this set.

Parameters:
Name Type Description
index number

The index of the tile within the set.

Source:
Returns:

The tile object. getTileX: function (index) {

    return this.tiles[index][0];

},
Type
object

getTileY(index) → {object}

Gets a Tile from this set.

Parameters:
Name Type Description
index number

The index of the tile within the set.

Source:
Returns:

The tile object. getTileY: function (index) {

    return this.tiles[index][1];

},
Type
object

setCollision(indexes, collides, layer)

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

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.

Source:

setCollisionBetween(start, stop, collides, layer)

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.

Source:

setCollisionByExclusion(indexes, collides, layer)

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.

Source:

<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:

setSpacing(tileMargin, tileSpacing)

Sets tile spacing and margins.

Parameters:
Name Type Argument Description
tileMargin number <optional>

The margin around the tiles in the sheet.

tileSpacing number <optional>

The spacing between the tiles in the sheet.

Source:

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.

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.

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:

setTileLocationCallback(x, y, width, height, 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.

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.

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