Class: Tileset

Phaser.Tilemaps. Tileset

A Tileset is a combination of an image containing the tiles and a container for data about each tile.


new Tileset(name, firstgid [, tileWidth] [, tileHeight] [, tileMargin] [, tileSpacing] [, tileProperties] [, tileData])

Parameters:
Name Type Argument Default Description
name string

The name of the tileset in the map data.

firstgid number

The first tile index this tileset contains.

tileWidth number <optional>
32

Width of each tile (in pixels).

tileHeight number <optional>
32

Height of each tile (in pixels).

tileMargin number <optional>
0

The margin around all tiles in the sheet (in pixels).

tileSpacing number <optional>
0

The spacing between each tile in the sheet (in pixels).

tileProperties object <optional>
{}

Custom properties defined per tile in the Tileset. These typically are custom properties created in Tiled when editing a tileset.

tileData object <optional>
{}

Data stored per tile. These typically are created in Tiled when editing a tileset, e.g. from Tiled's tile collision editor or terrain editor.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 9)

Members


<readonly> columns :number

The number of tile columns in the tileset.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 151)

firstgid :number

The starting index of the first tile index this Tileset contains.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 52)

<readonly, nullable> glTexture :WebGLTexture

The gl texture used by the WebGL renderer.

Type:
  • WebGLTexture
Since: 3.11.0
Source: src/tilemaps/Tileset.js (Line 131)

<readonly, nullable> image :Phaser.Textures.Texture

The cached image that contains the individual tiles. Use setImage to set.

Type:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 121)

name :string

The name of the Tileset.

Type:
  • string
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 43)

<readonly> rows :number

The number of tile rows in the the tileset.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 141)

<readonly> texCoordinates :Array.<object>

The look-up table to specific tile image texture coordinates (UV in pixels). Each element contains the coordinates for a tile in an object of the form {x, y}.

Type:
  • Array.<object>
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 171)

tileData :object

Tileset-specific data per tile that are typically defined in the Tiled editor, e.g. within the Tileset collision editor. This is where collision objects and terrain are stored.

Type:
  • object
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 111)

<readonly> tileHeight :number

The height of each tile (in pixels). Use setTileSize to change.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 71)

<readonly> tileMargin :number

The margin around the tiles in the sheet (in pixels). Use setSpacing to change.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 81)

tileProperties :object

Tileset-specific properties per tile that are typically defined in the Tiled editor in the Tileset editor.

Type:
  • object
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 101)

<readonly> tileSpacing :number

The spacing between each the tile in the sheet (in pixels). Use setSpacing to change.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 91)

<readonly> tileWidth :number

The width of each tile (in pixels). Use setTileSize to change.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 61)

<readonly> total :number

The total number of tiles in the tileset.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 161)

Methods


containsTileIndex(tileIndex)

Returns true if and only if this Tileset contains the given tile index.

Parameters:
Name Type Description
tileIndex number

The unique id of the tile across all tilesets in the map.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 238)
Returns:
Type
boolean

getTileCollisionGroup(tileIndex)

Get a tile's collision group that is stored in the Tileset. Returns null if tile index is not contained in this Tileset. This is typically defined within Tiled's tileset collision editor.

Parameters:
Name Type Description
tileIndex number

The unique id of the tile across all tilesets in the map.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 220)
Returns:
Type
object

getTileData(tileIndex)

Get a tile's data that is stored in the Tileset. Returns null if tile index is not contained in this Tileset. This is typically defined in Tiled and will contain both Tileset collision info and terrain mapping.

Parameters:
Name Type Description
tileIndex number

The unique id of the tile across all tilesets in the map.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 201)
Returns:
Type
object | undefined

getTileProperties(tileIndex)

Get a tiles properties that are stored in the Tileset. Returns null if tile index is not contained in this Tileset. This is typically defined in Tiled under the Tileset editor.

Parameters:
Name Type Description
tileIndex number

The unique id of the tile across all tilesets in the map.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 183)
Returns:
Type
object | undefined

getTileTextureCoordinates(tileIndex)

Returns the texture coordinates (UV in pixels) in the Tileset image for the given tile index. Returns null if tile index is not contained in this Tileset.

Parameters:
Name Type Description
tileIndex number

The unique id of the tile across all tilesets in the map.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 256)
Returns:

Object in the form { x, y } representing the top-left UV coordinate within the Tileset image.

Type
object

setImage(texture)

Sets the image associated with this Tileset and updates the tile data (rows, columns, etc.).

Parameters:
Name Type Description
texture Phaser.Textures.Texture

The image that contains the tiles.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 275)
Returns:

This Tileset object.

Type
Phaser.Tilemaps.Tileset

setSpacing( [margin] [, spacing])

Sets the tile margin & spacing and updates the tile data (rows, columns, etc.).

Parameters:
Name Type Argument Description
margin number <optional>

The margin around the tiles in the sheet (in pixels).

spacing number <optional>

The spacing between the tiles in the sheet (in pixels).

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 320)
Returns:

This Tileset object.

Type
Phaser.Tilemaps.Tileset

setTileSize( [tileWidth] [, tileHeight])

Sets the tile width & height and updates the tile data (rows, columns, etc.).

Parameters:
Name Type Argument Description
tileWidth number <optional>

The width of a tile in pixels.

tileHeight number <optional>

The height of a tile in pixels.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 296)
Returns:

This Tileset object.

Type
Phaser.Tilemaps.Tileset

updateTileData(imageWidth, imageHeight)

Updates tile texture coordinates and tileset data.

Parameters:
Name Type Description
imageWidth number

The (expected) width of the image to slice.

imageHeight number

The (expected) height of the image to slice.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 344)
Returns:

This Tileset object.

Type
Phaser.Tilemaps.Tileset