Class: Tile

Phaser.Tilemaps. Tile

A Tile is a representation of a single tile within the Tilemap. This is a lightweight data
representation, so its position information is stored without factoring in scroll, layer
scale or layer position.


new Tile(layer, index, x, y, width, height, baseWidth, baseHeight)

Parameters:
Name Type Description
layer Phaser.Tilemaps.LayerData

The LayerData object in the Tilemap that this tile belongs to.

index integer

The unique index of this tile within the map.

x integer

The x coordinate of this tile in tile coordinates.

y integer

The y coordinate of this tile in tile coordinates.

width integer

Width of the tile in pixels.

height integer

Height of the tile in pixels.

baseWidth integer

The base width a tile in the map (in pixels). Tiled maps support
multiple tileset sizes within one map, but they are still placed at intervals of the base
tile width.

baseHeight integer

The base height of the tile in pixels (in pixels). Tiled maps
support multiple tileset sizes within one map, but they are still placed at intervals of the
base tile height.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 11)

Extends

Members


alpha :number

The alpha value of the Game Object.

This is a global value, impacting the entire Game Object, not just a region of it.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 129)

alphaBottomLeft :number

The alpha value starting from the bottom-left of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 227)

alphaBottomRight :number

The alpha value starting from the bottom-right of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 257)

alphaTopLeft :number

The alpha value starting from the top-left of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 167)

alphaTopRight :number

The alpha value starting from the top-right of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 197)

baseHeight :integer

The map's base height of a tile in pixels. Tiled maps support multiple tileset sizes
within one map, but they are still placed at intervals of the base tile size.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 116)

baseWidth :integer

The map's base width of a tile in pixels. Tiled maps support multiple tileset sizes
within one map, but they are still placed at intervals of the base tile size.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 106)

<readonly> canCollide :boolean

True if this tile can collide on any of its faces or has a collision callback set.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 718)

collideDown :boolean

Whether the tile should collide with any object on the bottom side.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 195)

collideLeft :boolean

Whether the tile should collide with any object on the left side.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 168)

collideRight :boolean

Whether the tile should collide with any object on the right side.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 177)

<readonly> collides :boolean

True if this tile can collide on any of its faces.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 733)

collideUp :boolean

Whether the tile should collide with any object on the top side.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 186)

collisionCallback :function

Tile collision callback.

Type:
  • function
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 240)

collisionCallbackContext :object

The context in which the collision callback will be called.

Type:
  • object
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 249)

faceBottom :boolean

Whether the tile's bottom edge is interesting for collisions.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 231)

faceLeft :boolean

Whether the tile's left edge is interesting for collisions.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 204)

faceRight :boolean

Whether the tile's right edge is interesting for collisions.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 213)

faceTop :boolean

Whether the tile's top edge is interesting for collisions.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 222)

flipX :boolean

The horizontally flipped state of the Game Object.
A Game Object that is flipped horizontally will render inversed on the horizontal axis.
Flipping always takes place from the middle of the texture and does not impact the scale value.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/components/Flip.js (Line 17)

flipY :boolean

The vertically flipped state of the Game Object.
A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down)
Flipping always takes place from the middle of the texture and does not impact the scale value.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/components/Flip.js (Line 29)

<readonly> hasInterestingFace :boolean

True if this tile has any interesting faces.

Type:
  • boolean
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 748)

height :integer

The height of the tile in pixels.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 97)

index :integer

The index of this tile within the map data corresponding to the tileset, or -1 if this
represents a blank tile.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 60)

layer :Phaser.Tilemaps.LayerData

The LayerData in the Tilemap data that this tile belongs to.

Type:
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 51)

physics :object

An empty object where physics-engine specific information (e.g. bodies) may be stored.

Type:
  • object
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 269)

pixelX :number

The x coordinate of the top left of this tile in pixels. This is relative to the top left
of the layer this tile is being rendered within. This property does NOT factor in camera
scroll, layer scale or layer position.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 126)

pixelY :number

The y coordinate of the top left of this tile in pixels. This is relative to the top left
of the layer this tile is being rendered within. This property does NOT factor in camera
scroll, layer scale or layer position.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 137)

properties :object

Tile specific properties. These usually come from Tiled.

Type:
  • object
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 150)

rotation :number

The rotation angle of this tile.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 159)

<readonly, nullable> tilemap :Phaser.Tilemaps.Tilemap

The tilemap that contains this Tile. This will only return null if accessed from a LayerData
instance before the tile is placed within a StaticTilemapLayer or DynamicTilemapLayer.

Type:
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 797)

<readonly> tilemapLayer :Phaser.Tilemaps.StaticTilemapLayer|Phaser.Tilemaps.DynamicTilemapLayer

The tilemap layer that contains this Tile. This will only return null if accessed from a
LayerData instance before the tile is placed within a StaticTilemapLayer or
DynamicTilemapLayer.

Type:
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 780)

<readonly, nullable> tileset :Phaser.Tilemaps.Tileset

The tileset that contains this Tile. This will only return null if accessed from a LayerData
instance before the tile is placed within a StaticTilemapLayer or DynamicTilemapLayer.

Type:
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 763)

tint :number

The tint to apply to this tile. Note: tint is currently a single color value instead of
the 4 corner tint component on other GameObjects.

Type:
  • number
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 258)

visible :boolean

The visible state of the Game Object.

An invisible Game Object will skip rendering, but will still process update logic.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Visible.js (Line 31)

width :integer

The width of the tile in pixels.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 88)

x :integer

The x map coordinate of this tile in tile units.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 70)

y :integer

The y map coordinate of this tile in tile units.

Type:
  • integer
Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 79)

Methods


clearAlpha()

Clears all alpha values associated with this Game Object.

Immediately sets the alpha levels back to 1 (fully opaque).

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 77)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

containsPoint(x, y)

Check if the given x and y world coordinates are within this Tile. This does not factor in
camera scroll, layer scale or layer position.

Parameters:
Name Type Description
x number

The x coordinate to test.

y number

The y coordinate to test.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 279)
Returns:

True if the coordinates are within this Tile, otherwise false.

Type
boolean

copy(tile)

Copies the tile data & properties from the given tile to this tile. This copies everything
except for position and interesting faces.

Parameters:
Name Type Description
tile Phaser.Tilemaps.Tile

The tile to copy from.

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

This Tile object.

Type
Phaser.Tilemaps.Tile

destroy()

Clean up memory.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 492)

getBottom( [camera])

Gets the world Y position of the bottom side of the tile, factoring in the layer's position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 416)
Returns:
Type
number

getBounds( [camera] [, output])

Gets the world rectangle bounding box for the tile, factoring in the layers position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

output object <optional>

[description]

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 436)
Returns:
Type
Phaser.Geom.Rectangle | object

getCenterX( [camera])

Gets the world X position of the center of the tile, factoring in the layer's position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 460)
Returns:
Type
number

getCenterY( [camera])

Gets the world Y position of the center of the tile, factoring in the layer's position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 476)
Returns:
Type
number

getCollisionGroup()

The collision group for this Tile, defined within the Tileset. This returns a reference to
the collision group stored within the Tileset, so any modification of the returned object
will impact all tiles that have the same index as this tile.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 326)
Returns:

tileset

Type
object

getLeft( [camera])

Gets the world X position of the left side of the tile, factoring in the layers position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 357)
Returns:
Type
number

getRight( [camera])

Gets the world X position of the right side of the tile, factoring in the layer's position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 375)
Returns:
Type
number

getTileData()

The tile data for this Tile, defined within the Tileset. This typically contains Tiled
collision data, tile animations and terrain information. This returns a reference to the tile
data stored within the Tileset, so any modification of the returned object will impact all
tiles that have the same index as this tile.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 341)
Returns:

tileset

Type
object

getTop( [camera])

Gets the world Y position of the top side of the tile, factoring in the layer's position,
scale and scroll.

Parameters:
Name Type Argument Description
camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use to perform the check.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 393)
Returns:
Type
number

intersects(x, y, right, bottom)

Check for intersection with this tile. This does not factor in camera scroll, layer scale or
layer position.

Parameters:
Name Type Description
x number

The x axis in pixels.

y number

The y axis in pixels.

right number

The right point.

bottom number

The bottom point.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 505)
Returns:
Type
boolean

isInteresting(collides, faces)

Checks if the tile is interesting.

Parameters:
Name Type Description
collides boolean

If true, will consider the tile interesting if it collides on any side.

faces boolean

If true, will consider the tile interesting if it has an interesting face.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 527)
Returns:

True if the Tile is interesting, otherwise false.

Type
boolean

resetCollision( [recalculateFaces])

Reset collision status flags.

Parameters:
Name Type Argument Default Description
recalculateFaces boolean <optional>
true

Whether or not to recalculate interesting faces for this tile and its neighbors.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 546)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile

resetFaces()

Reset faces.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 583)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile

resetFlip()

Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 124)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

setAlpha( [topLeft] [, topRight] [, bottomLeft] [, bottomRight])

Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders.
Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque.

If your game is running under WebGL you can optionally specify four different alpha values, each of which
correspond to the four corners of the Game Object. Under Canvas only the topLeft value given is used.

Parameters:
Name Type Argument Default Description
topLeft number <optional>
1

The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object.

topRight number <optional>

The alpha value used for the top-right of the Game Object. WebGL only.

bottomLeft number <optional>

The alpha value used for the bottom-left of the Game Object. WebGL only.

bottomRight number <optional>

The alpha value used for the bottom-right of the Game Object. WebGL only.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 92)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

setCollision(left [, right] [, up] [, down] [, recalculateFaces])

Sets the collision flags for each side of this tile and updates the interesting faces list.

Parameters:
Name Type Argument Default Description
left boolean

Indicating collide with any object on the left.

right boolean <optional>

Indicating collide with any object on the right.

up boolean <optional>

Indicating collide with any object on the top.

down boolean <optional>

Indicating collide with any object on the bottom.

recalculateFaces boolean <optional>
true

Whether or not to recalculate interesting faces
for this tile and its neighbors.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 601)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile

setCollisionCallback(callback, context)

Set a callback to be called when this tile is hit by an object. The callback must true for
collision processing to take place.

Parameters:
Name Type Description
callback function

Callback function.

context object

Callback will be called within this context.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 646)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile

setFlip(x, y)

Sets the horizontal and vertical flipped state of this Game Object.

Parameters:
Name Type Description
x boolean

The horizontal flipped state. false for no flip, or true to be flipped.

y boolean

The horizontal flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 105)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

setFlipX(value)

Sets the horizontal flipped state of this Game Object.

Parameters:
Name Type Description
value boolean

The flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 71)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

setFlipY(value)

Sets the vertical flipped state of this Game Object.

Parameters:
Name Type Description
value boolean

The flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 88)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

setSize(tileWidth, tileHeight, baseWidth, baseHeight)

Sets the size of the tile and updates its pixelX and pixelY.

Parameters:
Name Type Description
tileWidth integer

The width of the tile in pixels.

tileHeight integer

The height of the tile in pixels.

baseWidth integer

The base width a tile in the map (in pixels).

baseHeight integer

The base height of the tile in pixels (in pixels).

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 674)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile

setVisible(value)

Sets the visibility of this Game Object.

An invisible Game Object will skip rendering, but will still process update logic.

Parameters:
Name Type Description
value boolean

The visible state of the Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Visible.js (Line 63)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

toggleFlipX()

Toggles the horizontal flipped state of this Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 41)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

toggleFlipY()

Toggles the vertical flipped state of this Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 56)
Returns:

This Game Object instance.

Type
Phaser.Tilemaps.Tile

updatePixelXY()

Used internally. Updates the tile's world XY position based on the current tile size.

Since: 3.0.0
Source: src/tilemaps/Tile.js (Line 699)
Returns:

This Tile object.

Type
Phaser.Tilemaps.Tile