Seanba / Tiled2Unity

Export Tiled Map Editor (TMX) files into Unity
Other
497 stars 120 forks source link

SpriteDepthInMap ignores ExportScale of Map #91

Closed falkokoetter closed 7 years ago

falkokoetter commented 7 years ago

First of all, thank you for all your work on Tiled2Unity. :-)

I found an issue in depth buffering an exported Tiled map. It only works when the ExportScale of the map is 1. Otherwise, the calculated values are too small and tiles are mosty displayed above sprites,

The affected code is line 55 in SpriteDepthInMap.cs : float depth_z = (spritePosition.y / mapRect.height) + (depthPerLayer * this.InteractWithLayer);

If the export scale is different than one, it will not work, as the sprite position is in units and the mapRect height is in pixels.

Dividing the sprite position by the export scale of the map fixes this issue: float depth_z = (spritePosition.y / this.AttachedMap.ExportScale / mapRect.height) + (depthPerLayer * this.InteractWithLayer);

I tested this with an export scale of 0.0625 (16 pixels per unit when exporting from tiled).

Seanba commented 7 years ago

Thanks for finding a fix for this. I'll put up a new version of Tiled2Unity soon.

Seanba commented 7 years ago

Version 1.0.10.3 was just made public with this fix. Thanks again!