Description
I have a flat-topped tilemap setup in Tiled as follows:
<map version="1.0" orientation="hexagonal" renderorder="right-down" width="16" height="16" tilewidth="75" tileheight="65" hexsidelength="40" staggeraxis="x" staggerindex="odd" nextobjectid="9">
I'm having an issue with 'coordinateForPoint' not returning the correct coordinates for me.
I narrowed it down to this method in 'screenToTileCoords':
if (tilemap.staggerX == true) {
s = tilemap.sideLengthX
r = (tileWidth - tilemap.sideLengthX) / 2
h = tileHeight / 2
pixelX -= r
sectionX = pixelX / (r + s)
sectionY = pixelY / (h * 2)
// y-offset
if tilemap.doStaggerX(Int(sectionX)){
sectionY -= 0.5
}
Specifically: pixelX -= r
. This causes pixels in the left-side tip of a flat-topped hex tile to be calculated to the previous X column. Removing this line causes pixels in the right-side tip of a flat-topped hex tile to be calculated to the next X column.
Barring any significantly more complicated calculations to figure out the column of an angled side, I split the difference with pixelX -= (r / 2)
and it seems to be working 'good enough' for me. I'd appreciate your thoughts!