I appreciate this might be niche, but I came to explore TiledCS using the 'Tiled' example tileset texture tmw_desert_spacing.png and I was confused for a bit when I got odd results!
This particular example tileset has a Spacing property of 1 and a Margin property of 1. I believe these are pixel values, measuring (in Spacing) the number of pixels 'between' successive tiles in the texture, and (in Margin) the number of pixels 'in' before the first tile starts. There is only 1 integer value for each property so I assume it applies to both horizontal and vertical measurements.
Anyway, when it's used with TiledCS, the TiledMap.GetSourceRect seems to ignore these properties and return the rectangle from the texture as if there was no Margin or Spacing.
I have a 5 minute play and realised that TileMap.GetSourceRect needs to do something like this;
(line 710 ish, TiledMap.cs)
x = tileset.Margin + num * (tileset.TileWidth + tileset.Spacing),
y = tileset.Margin + num2 * (tileset.TileHeight + tileset.Spacing),
The source texture;
Without Spacing & Margin observed
With Spacing and Margin observed
Hope this makes sense! There might well be other places in the code where this would have to be adapted of course, and I guess this isn't much of a priority to anyone else, but the initial result puzzled me for a while at least.
I appreciate this might be niche, but I came to explore TiledCS using the 'Tiled' example tileset texture tmw_desert_spacing.png and I was confused for a bit when I got odd results!
This particular example tileset has a Spacing property of 1 and a Margin property of 1. I believe these are pixel values, measuring (in Spacing) the number of pixels 'between' successive tiles in the texture, and (in Margin) the number of pixels 'in' before the first tile starts. There is only 1 integer value for each property so I assume it applies to both horizontal and vertical measurements.
Anyway, when it's used with TiledCS, the TiledMap.GetSourceRect seems to ignore these properties and return the rectangle from the texture as if there was no Margin or Spacing.
I have a 5 minute play and realised that TileMap.GetSourceRect needs to do something like this;
(line 710 ish, TiledMap.cs)
The source texture;
Without Spacing & Margin observed
With Spacing and Margin observed
Hope this makes sense! There might well be other places in the code where this would have to be adapted of course, and I guess this isn't much of a priority to anyone else, but the initial result puzzled me for a while at least.