Phaser API Documentation

  Version: 
Filter

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

Constructor:

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

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.

tileOffset object <optional> {x: 0, y: 0}

Tile texture drawing offset.

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

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 167)
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 53)
Focus
Focus
<readonly, nullable> glTexture: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper
Focus
Focus

Description:

The gl texture used by the WebGL renderer.

Type:
Since: 3.11.0
Source: src/tilemaps/Tileset.js (Line 147)
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 137)
Focus
Focus
name: string
Focus
Focus

Description:

The name of the Tileset.

Type:
string
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 44)
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 157)
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 187)
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 112)
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 72)
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 82)
Focus
Focus
tileOffset: Phaser.Math.Vector2
Focus
Focus

Description:

Controls the drawing offset from the tile origin. Defaults to 0x0, no offset.

Type:
Since: 3.60.0
Source: src/tilemaps/Tileset.js (Line 122)
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 102)
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 92)
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 62)
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 177)
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
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 254)
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
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 236)
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
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 217)
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
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 199)
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
Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 272)
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.

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

Description:

Sets the tile margin and 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.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 347)
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.

Since: 3.0.0
Source: src/tilemaps/Tileset.js (Line 323)
Focus
Focus
updateTileData(imageWidth, imageHeight, [offsetX], [offsetY])
Focus
Focus

Description:

Updates tile texture coordinates and tileset data.

Parameters:

name type arguments description
imageWidth number

The (expected) width of the image to slice.

imageHeight number

The (expected) height of the image to slice.

offsetX number <optional>

The x offset in the source texture where the tileset starts.

offsetY number <optional>

The y offset in the source texture where the tileset starts.

Returns:
Description:

This Tileset object.

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