TiledCS icon indicating copy to clipboard operation
TiledCS copied to clipboard

Fixed TiledMap.GetSourceRect

Open Frankfires opened this issue 3 years ago • 7 comments

TiledMap.GetSourceRect wasn't returning the correct frame with tile spacing in mind. TODO: figure out what margins do and update this method again

Frankfires avatar Aug 19 '22 21:08 Frankfires

Hey

Thanks for the fix! I would like to test it out myself as well and see what I can do with the margin after the merge. Can you share your tileset with me? I never had a tileset with margins or spacing before. And to be honest, I still do not understand why some artists do that. lol

With kind regards, TheBoneJarmer

TheBoneJarmer avatar Aug 20 '22 06:08 TheBoneJarmer

Giving spacing ( and I think margins too ) to tilesets is kinda helps you differ between sort of similar tiles by adding a gaps of pixels that are skipped over and not rendered in between each tile:

image

The Tiled tileset editor when being prompted for an image also asks you if you margined or spaced out your tiles, this way it can render your tiles correctly by skipping over 1 pixel every frame:

image image

If I were to remove the spacing from the tileset properties but keep it in the sprite my tiles when rendered would look something like this:

image image

This is also what a rendered map that uses TiledMap.GetSourceRect to get each tile's frame would look like if I tried to render tiles with spacing. ( not good )

By adding the tileset's spacing multiplied by its frame onto the frame's x and y values you'd be skipping over the spacing that was inputted allowing the tiles to be rendered properly.

Frankfires avatar Aug 20 '22 14:08 Frankfires

Hey

Sorry for the late reply. Thanks a lot for the explanation! That does make sense indeed. I do have one question though. Do you think you can still share one of your test maps with me, please? That way I can test it properly and round things up.

With kind regards, TheBoneJarmer

TheBoneJarmer avatar Aug 21 '22 09:08 TheBoneJarmer

Hey @Frankfires

I still have not heard back from you. Do you mind to share your tileset with me so I can properly test things? Thanks!

With kind regards, TheBoneJarmer

TheBoneJarmer avatar Aug 26 '22 06:08 TheBoneJarmer

If it helps at all, here is another texture which requires Spacing=1 and Margin=1... tmw_desert_spacing

robsoft avatar Oct 11 '22 12:10 robsoft

Did a quick review, Not knowing much about the properties available on the class, assuming that the Spacing is a valid property on tileSet, then I think the code could be merged. However, may want to adjust the math to do the addition first, and the multiply second, so only 1 multiply is performed vs 2 per line.

kaltinril avatar Apr 03 '23 02:04 kaltinril

It appears #94 has an added fix that also includes margins in the position calculation. May want to use that one instead of the PR from this one.

kaltinril avatar Apr 03 '23 02:04 kaltinril