Hexagon Tilemap render order needs reviewing

I’ve been testing making a hexagon map with tiles larger than the map’s tilesize.

I’ve included a tmx/tsx/png for the test I’m using. I simply added it to samples/test resources and replaced the current hex map test tmx with mine.

What I assume is happening is that it’s treating the top staggered row all as a single row and rendering it like:
0,0 - 1,0 - 2,0 - 3,0 etc…
0,1 - 1,1 - 2,1 - 3,1 etc…

Though since a hexagon map is staggered, to prevent strange overlapping behavior of larger than map tilesize tiles it should render like:
0,0 - 2,0 - 4,0 etc…
1,0 - 3,0 - 5,0 etc…
0,1 - 2,1 - 4,0 etc…
1,1 - 3,1 - 5,1 etc…

I’ve included a screenshot, since it’s fairly clear from it what’s going on without having to load up the sample.


outwitter_tile_example.png (171.5 KB)


outwitters.zip (44.7 KB)

I’ve been working on trying to fix this issue on my own, since I’d like to use a 2.5d hexagon tilemap. I just got the rendering working properly, but haven’t gotten into testing all the other position checking functions.

Mainly what I’ve done is stored a simple object in atlasIndexArray:
{zOrder: z, tileIndex: i}

Instead of a single value z that makes the assumptions that the tileIndex is also the zOrder (I can only assume that 2.5d isometric tiles run into the same issue but haven’t tested, if so adding a simple orientation check for that along side my hexagon check should add the functionality for it.

Anyway, once I did that it all sort of fell into place. I replaced all the z = 0 | pos.x + pos.y * this._layerSize.width, with something like:
var zC = this._getZCouplet(pos);

Which creates the simple zOrder/tileIndex object above. I changed the atlasIndexForExistantZ to compare tileIndex and atlasIndexForNewZ to compare zOrder.

All the other tileMap tests seem unaffected, though they will end up taking up more memory since they’ll be storing an object instead of just a number in the atlasArray.

Attached is the result. I wouldn’t be surprised if I run into some issues later if I change z values, or on hit detection, but I’ll cross those bridges when I come to them. I also noticed there are some functions labeled as not yet implemented for Hexagon maps. If I need them, I suppose I’ll write them when the time comes.

Hi, I can’t open your file in tiled, what program do you use?

The current version of Tiled doesn’t support Hexagon Tileset/maps, you have to compile a fork @ https://github.com/maq777/tiled

It will be able to open the hexmap in the samples/tests as well.