1. Home
  2. Game dev
  3. JSON overview
  4. Tileset coordinate IDs

Tileset coordinate IDs

These coordinate IDs are a little bit more tricky than classic ones, because some tilesets can have padding and tile spacing.

For a given tileId (coordinate ID of a specific tile), you can get the atlas image pixel coordinates like this:

// Get "grid-based" coordinate of the tileId 
var gridTileX = tileId - atlasGridBaseWidth * Std.int( tileId / atlasGridBaseWidth );

// Get the atlas pixel coordinate 
var pixelTileX = padding + gridTileX * ( gridSize + spacing );

Same goes for the Y coordinates:

// Get "grid-based" coordinate of the tileId 
var gridTileY = Std.int( tileId / atlasGridBaseWidth )

// Get the atlas pixel coordinate 
var pixelTileY = padding + gridTileY * ( gridSize + spacing );