Skip to main content
Version: Phaser v4.0.0-rc.6

Tileset

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

nametypeoptionaldefaultdescription
namestringNoThe name of the tileset in the map data.
firstgidnumberNoThe first tile index this tileset contains.
tileWidthnumberYes32Width of each tile (in pixels).
tileHeightnumberYes32Height of each tile (in pixels).
tileMarginnumberYes0The margin around all tiles in the sheet (in pixels).
tileSpacingnumberYes0The spacing between each tile in the sheet (in pixels).
tilePropertiesobjectYes"{}"Custom properties defined per tile in the Tileset. These typically are custom properties created in Tiled when editing a tileset.
tileDataobjectYes"{}"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.
tileOffsetobjectYes"{x: 0, y: 0}"Tile texture drawing offset.

Scope: static

Source: src/tilemaps/Tileset.js#L10
Since: 3.0.0

Public Members

animationSearchThreshold

animationSearchThreshold: number

Description:

The number of frames above which a tile is considered to have

many animation frames. This is used to optimize rendering.

If a tile has fewer frames than this, frames are searched using

a linear search. If a tile has more, frames are searched using

a binary search.

Source: src/tilemaps/Tileset.js#L198
Since: 4.0.0


columns

columns: number

Description:

The number of tile columns in the tileset.

Source: src/tilemaps/Tileset.js#L167
Since: 3.0.0


firstgid

firstgid: number

Description:

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

Source: src/tilemaps/Tileset.js#L53
Since: 3.0.0


glTexture

glTexture: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

Description:

The gl texture used by the WebGL renderer.

Source: src/tilemaps/Tileset.js#L147
Since: 3.11.0


image

image: Phaser.Textures.Texture

Description:

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

Source: src/tilemaps/Tileset.js#L137
Since: 3.0.0


maxAnimationLength

maxAnimationLength: number

Description:

The maximum length of any animation in this tileset, in frames.

This is used internally to optimize rendering.

It is updated when createAnimationDataTexture is called.

Source: src/tilemaps/Tileset.js#L212
Since: 4.0.0


name

name: string

Description:

The name of the Tileset.

Source: src/tilemaps/Tileset.js#L44
Since: 3.0.0


rows

rows: number

Description:

The number of tile rows in the the tileset.

Source: src/tilemaps/Tileset.js#L157
Since: 3.0.0


texCoordinates

texCoordinates: Array.<object>

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

Source: src/tilemaps/Tileset.js#L187
Since: 3.0.0


tileData

tileData: object

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.

Source: src/tilemaps/Tileset.js#L112
Since: 3.0.0


tileHeight

tileHeight: number

Description:

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

Source: src/tilemaps/Tileset.js#L72
Since: 3.0.0


tileMargin

tileMargin: number

Description:

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

Source: src/tilemaps/Tileset.js#L82
Since: 3.0.0


tileOffset

tileOffset: Phaser.Math.Vector2

Description:

Controls the drawing offset from the tile origin.

Defaults to 0x0, no offset.

Source: src/tilemaps/Tileset.js#L122
Since: 3.60.0


tileProperties

tileProperties: object

Description:

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

Tileset editor.

Source: src/tilemaps/Tileset.js#L102
Since: 3.0.0


tileSpacing

tileSpacing: number

Description:

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

Source: src/tilemaps/Tileset.js#L92
Since: 3.0.0


tileWidth

tileWidth: number

Description:

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

Source: src/tilemaps/Tileset.js#L62
Since: 3.0.0


total

total: number

Description:

The total number of tiles in the tileset.

Source: src/tilemaps/Tileset.js#L177
Since: 3.0.0


Public Methods

containsTileIndex

<instance> containsTileIndex(tileIndex)

Description:

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

Parameters:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.

Returns: boolean - undefined

Source: src/tilemaps/Tileset.js#L311
Since: 3.0.0


createAnimationDataTexture

<instance> createAnimationDataTexture(renderer)

Description:

Creates a new WebGLTexture for the tileset's animation data.

Parameters:

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe renderer to use.

Returns: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper - The new WebGLTexture.

Source: src/tilemaps/Tileset.js#L584
Since: 4.0.0


getAnimatedTileId

<instance> getAnimatedTileId(tileIndex, milliseconds)

Description:

Returns the ID of the tile to use, given a base tile and time,

according to the tile's animation properties.

If the tile is not animated, this method returns the base tile ID.

Parameters:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.
millisecondsnumberNoThe current time in milliseconds.

Returns: number - The tile ID to use, or null if the tile is not contained in this tileset.

Source: src/tilemaps/Tileset.js#L329
Since: 4.0.0


getAnimationDataIndexMap

<instance> getAnimationDataIndexMap(renderer)

Description:

Get or create the map from tile index to animation data index.

This is used by TilemapGPULayer to animate tiles.

Parameters:

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe renderer to use.

Returns: Map.<number, number> - The map from tile index to animation data index.

Source: src/tilemaps/Tileset.js#L565
Since: 4.0.0


getAnimationDataTexture

<instance> getAnimationDataTexture(renderer)

Description:

Get or create the texture containing the animation data for this tileset.

This is used by TilemapGPULayer to animate tiles.

Parameters:

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe renderer to use.

Returns: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper - The animation data texture.

Source: src/tilemaps/Tileset.js#L546
Since: 4.0.0


getTileCollisionGroup

<instance> getTileCollisionGroup(tileIndex)

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:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.

Returns: object - undefined

Source: src/tilemaps/Tileset.js#L293
Since: 3.0.0


getTileData

<instance> getTileData(tileIndex)

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:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.

Returns: object, undefined - undefined

Source: src/tilemaps/Tileset.js#L274
Since: 3.0.0


getTileProperties

<instance> getTileProperties(tileIndex)

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:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.

Returns: object, undefined - undefined

Source: src/tilemaps/Tileset.js#L256
Since: 3.0.0


getTileTextureCoordinates

<instance> getTileTextureCoordinates(tileIndex)

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:

nametypeoptionaldescription
tileIndexnumberNoThe unique id of the tile across all tilesets in the map.

Returns: object - Object in the form { x, y } representing the top-left UV coordinate

within the Tileset image.

Source: src/tilemaps/Tileset.js#L384
Since: 3.0.0


setImage

<instance> setImage(texture)

Description:

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

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe image that contains the tiles.

Returns: Phaser.Tilemaps.Tileset - This Tileset object.

Source: src/tilemaps/Tileset.js#L403
Since: 3.0.0


setSpacing

<instance> setSpacing([margin], [spacing])

Description:

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

Parameters:

nametypeoptionaldescription
marginnumberYesThe margin around the tiles in the sheet (in pixels).
spacingnumberYesThe spacing between the tiles in the sheet (in pixels).

Returns: Phaser.Tilemaps.Tileset - This Tileset object.

Source: src/tilemaps/Tileset.js#L459
Since: 3.0.0


setTileSize

<instance> setTileSize([tileWidth], [tileHeight])

Description:

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

Parameters:

nametypeoptionaldescription
tileWidthnumberYesThe width of a tile in pixels.
tileHeightnumberYesThe height of a tile in pixels.

Returns: Phaser.Tilemaps.Tileset - This Tileset object.

Source: src/tilemaps/Tileset.js#L435
Since: 3.0.0


updateTileData

<instance> updateTileData(imageWidth, imageHeight, [offsetX], [offsetY])

Description:

Updates tile texture coordinates and tileset data.

Parameters:

nametypeoptionaldefaultdescription
imageWidthnumberNoThe (expected) width of the image to slice.
imageHeightnumberNoThe (expected) height of the image to slice.
offsetXnumberYes0The x offset in the source texture where the tileset starts.
offsetYnumberYes0The y offset in the source texture where the tileset starts.

Returns: Phaser.Tilemaps.Tileset - This Tileset object.

Source: src/tilemaps/Tileset.js#L483
Since: 3.0.0