2
« on: February 19, 2013, 01:35:00 pm »
Sorry I think I asked the question incorrectly, the top-left sort order is fine.
Here's the scenario (top-down view, x,y co-ordinate system is top-left) :
1) Fence tile is at 0,1 on tilemap and player sprite (not a tile on the tile map) is at the equivalent location of 0,0.5 on the tile map. The player sprite is drawn behind the fence.
2) Fence is at tile 0,1 and player is at the equivalent location of 0,1.5 on the tile map. The player is drawn in front of the fence.
If I weren't doing this through unity I'd sort all tiles and sprites by their y co-ordinate and layer, and then render them in that order.
The only way I could think about re-creating this process using the tilemap was by having each row of tiles in the tilemap have a specific z value, and this z value increases
as you go down the y-axis. The player sprite would have have it's z-value changed depending upon it's y-axis location.
However looks like the tile map only increments the z value of the chunks created( somewhere around line 306 of TileMapBuilderUtil).
So...I tried adding calculated z values for tile vertices created in RenderMeshBuilder.BuildForChunk i.e. float z = -((layer.numRows * layer.divY - 1) - (baseY + y)) * someZDepthFactor;
and got the ordering working somewhat. However there was some inconsistency in draw order between transparent objects at the same z value (e.g. player sprite and
fence tile). A search on the interwebs revealed that objects with transparency shaders sort by object pivots, and multiple transparent objects that have been
meshed together and have one pivot don't sort well. I changed the materials shaders to use SolidVertexColor and it did seem to fix the problem...albeit with no transparency.
I don't know if that made any sense, but is there an easier solution you can think of?