Tilemap col/row to x/y conversion

Is there a way to easily convert a tilemap col/row position to an x/y coorindates?

Some block refer to tilemap col/row positions and others refer to x/y coordinates. So far the only way I know to get the actual x/y coordinates is to turn on physics for my character, walk them over the tilemap in game, and read the co/row position physics is showing.

I need both the col/row and x/y values because I am trying to create an event that willcause the camera to refocus on a part of the map when my character crosses a certain area. The camera focus block uses x/y coordinates and the tilemap overlap blocks uses col/row positions.

Tilemap tiles are 16x16. If you have a tilemap position like (0, 3), you can get x/y coordinates by multiplying by 16:

(0, 3) tilecoords * 16 = (0, 48) x/y coords

Keep in mind: this gives you the x/y coordinates of the top and left of the tile. If you want to get closer to the center (“center” is funny because with an even number, the center is between pixels), you’ll want to also add half the tile width/height (8).

(0, 3) * 16 = (0, 48)
              (0, 48) + 8 = (8, 56) // "center" of tile at (0, 3)

Does that help?

1 Like

Thanks @jacob_c - nice and clear explanation.

1 Like

@techahoynyc you can also add the microsoft/pxt-tilemaps extension which includes some blocks for converting between coordinates. Just click the “+ Extension” button under advanced in the toolbox and paste microsoft/pxt-tilemaps into the search box.