Tuesday, October 8, 2013

Converting from Screen to Map Coordinates in Isometric 2D Games

This article here provides a great explanation on this.

Formulae in summary:

From screen coordinates to tile x,y

map.x = screen.x / TILE_WIDTH + screen.y / TILE_HEIGHT;
map.y = screen.y / TILE_HEIGHT - screen.x / TILE_WIDTH;


From tile x,y to screen coordinates

screen.x = (map.x - map.y) * TILE_WIDTH_HALF;
screen.y = (map.x + map.y) * TILE_HEIGHT_HALF;



Note: these only work if the iso map is skewed at 45 degrees. If it's skewed in 30 degrees or 60 degrees, trigonometry will be needed.

No comments:

Post a Comment