I know this is an old post, but I want to update it, as some people can still find answers to this problem, as before. However, I understood this myself. There is also a much better way to do this so that there are no problems with overlapping tiles.
The code is as simple as this one:
mouse_grid_x = floor((mouse_y / tile_height) + (mouse_x / tile_width)); mouse_grid_y = floor((-mouse_x / tile_width) + (mouse_y / tile_height));
mouse_x and mouse_y are the coordinates of the mouse screen.
tile_height and tile_width are the actual size of the tile, not the image itself. As you see in my example image, I added dirt to my tile, this is just to simplify rendering, the actual size is 24 x 12. The coordinates are also βgenderβ to keep the grid of results x and y rounded down.
Also note that I draw these fragments from y = 0 and x = tile_with / 2 (red dot). This means that my 0.0 actually starts at the top corner of the tile (tilted), and not outdoors. See these tiles as rotated squares, you still want to start with 0.0 pixels.
Palis will be displayed starting from Y = 0 and X = 0 to the size of the card. After rendering the first line, you skip a few pixels down and left. This will cause the next row of tiles to overlap the first, which is a great way to keep layers matching. You must display the tiles, and then everything on that tile before moving on to the next.
I will also add a visualization example:
for (yy = 0; yy < map_height; yy++) { for (xx = 0; xx < map_width; xx++) { draw tiles here with tile coordinates: tile_x = (xx * 12) - (yy * 12) - (tile_width / 2) tile_y = (yy * 6) + (xx * 6) also draw whatever is on this tile here before moving on } }

Ernst albrigtsen
source share