1. Home
  2. Docs
  3. LEd documentation
  4. JSON
  5. Coordinate IDs (coordId)

Coordinate IDs (coordId)

General concept

Some layers use coordIds to store their data. A coordId is always the result of the following formula:

var coordId = gridBasedX + gridBasedY * gridBasedWidth;

This means that you can get gridBasedY from a coordId like this:

var gridBasedY = Math.floor( coordId / gridBasedWidth );
var gridBasedX = coordId - gridBasedY * gridBasedWidth

Please note that grid based values are usually prefixed with a c:

  • cx/cy for a grid based X/Y
  • cWid/cHei for a grid based width/height

Tileset coordinate IDs

These ones are a little bit more tricky, 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 );