Phaser API Documentation

  Version: 
worldToTileX(worldX, [snapToFloor], [camera])

Description:

Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the layers position, scale and scroll.

You cannot call this method for Isometric or Hexagonal tilemaps as they require both worldX and worldY values to determine the correct tile, instead you should use the worldToTileXY method.

Parameters:

name type arguments description
worldX number

The x coordinate to be converted, in pixels, not tiles.

snapToFloor boolean <optional>

Whether or not to round the tile coordinate down to the nearest integer.

camera Phaser.Cameras.Scene2D.Camera <optional>

The Camera to use when calculating the tile index from the world values.

Returns:
Description:

The tile X coordinate based on the world value.

Type:
  • number
Since: 3.50.0