Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Tilemaps . Tileset

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Tilemaps . Tileset

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

Constructor:

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

Parameters:

name type arguments 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
Focus
Focus

Description:

The number of tile columns in the tileset.

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

Description:

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

Type:
number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 52)
Focus
Focus
<readonly, nullable> glTexture: WebGLTexture
Focus
Focus

Description:

The gl texture used by the WebGL renderer.

Type:
WebGLTexture
Since: 3.11.0
Source: src/tilemaps/Tileset.js (Line 131)
Focus
Focus
<readonly, nullable> image: Phaser.Textures.Texture
Focus
Focus

Description:

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

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

Description:

The name of the Tileset.

Type:
string
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 43)
Focus
Focus
<readonly> rows: number
Focus
Focus

Description:

The number of tile rows in the the tileset.

Type:
number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 141)
Focus
Focus
<readonly> texCoordinates: Array.<object>
Focus
Focus

Description:

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)
Focus
Focus
tileData: object
Focus
Focus

Description:

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)
Focus
Focus
<readonly> tileHeight: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 71)
Focus
Focus
<readonly> tileMargin: number
Focus
Focus

Description:

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)
Focus
Focus
tileProperties: object
Focus
Focus

Description:

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)
Focus
Focus
<readonly> tileSpacing: number
Focus
Focus

Description:

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)
Focus
Focus
<readonly> tileWidth: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 61)
Focus
Focus
<readonly> total: number
Focus
Focus

Description:

The total number of tiles in the tileset.

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

Methods

containsTileIndex(tileIndex)
Focus
Focus

Description:

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.

Type:
  • boolean
Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 238)
Focus
Focus
getTileCollisionGroup(tileIndex)
Focus
Focus

Description:

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.

Type:
  • object
Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 220)
Focus
Focus
getTileData(tileIndex)
Focus
Focus

Description:

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.

Type:
  • object
  • undefined
Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 201)
Focus
Focus
getTileProperties(tileIndex)
Focus
Focus

Description:

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.

Type:
  • object
  • undefined
Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 183)
Focus
Focus
getTileTextureCoordinates(tileIndex)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • object
Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 256)
Focus
Focus
setImage(texture)
Focus
Focus

Description:

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.

Returns:
Description:

This Tileset object.

Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 275)
Focus
Focus
setSpacing([margin], [spacing])
Focus
Focus

Description:

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

Parameters:

name type arguments 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).

Returns:
Description:

This Tileset object.

Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 320)
Focus
Focus
setTileSize([tileWidth], [tileHeight])
Focus
Focus

Description:

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

Parameters:

name type arguments description
tileWidth number <optional>

The width of a tile in pixels.

tileHeight number <optional>

The height of a tile in pixels.

Returns:
Description:

This Tileset object.

Examples:
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 296)
Focus
Focus
updateTileData(imageWidth, imageHeight)
Focus
Focus

Description:

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.

Returns:
Description:

This Tileset object.

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