Offset tileset grid?

Hi, I’ve got a number of tileset images that have been saved with a single pixel “border” on the top and right. Apart from that the tiles are 20px with 20px spacing, so a 3x5 tile image is 101x181. I can crop these myself outside of Tiled, obviously, but I was wondering if there’s some way in the editor to get it to offset the grid to chop off the border without me having to process the images.

You can set the Margin property in the tileset to 1px.

The margin setting I can see applies to all sides of the image. The tileset images I have only have a margin on the top and right.

Margin would work if there was a way to stipulate separate T,R,B,L margins. Is there such a feature?

The margin setting in Tiled only applies to the top and left I think. The bottom and right margins are used as tiles if they’re big enough, but usually they’re not so they’re just ignored.

Okay. Unfortunately that’s not functionally different for my situation as it still results in losing the first column of pixels in every tile if I set the margin to 1.

It shouldn’t. Margins are on the whole tileset image only, they only take off the top and leftmost pixel(s) of the whole tileset image. Spacing is the one that removes pixels everywhere.

Yes, but by treating the first pixel column as a margin the grid is then off by one on every tile.

As I said, the tileset image has a margin on the top and right, so if the margin is set to 0 the Y grid alignment is incorrect and I lose the bottom row of every tile and if it is set to 1 then the X grid alignment is incorrect and I lose the left column of every tile.

I’m sorry, I don’t think I understand how your tileset is set up. Would you mind posting it?

Sure, here’s an example of the format. Don’t expect me to explain why they’re formatted like this as I had nothing to do with the project they come from.

example

Oh, I see. I must’ve misread the top and right part, thought you said top and left. Unfortunately the only thing you can do is crop off the top row of pixels in an image editor and use a margin of 0 ):

If Tiled had separate top and left margin entry (right and bottom aren’t necessary as long as the margins are smaller than the tile size), then that would’ve helped here.

Edit: if modifying the image isn’t an option (e.g. if it has to be like that in-engine), you could use a different image while editing from what you use in-game, or you could use a margin of 0 and deal with the 1px of garbage at the top of every tile.

Yeah, such a setting would help in this case. It’s rarely needed, but I think it would still be worth adding, though I’d probably do that as part of issue Change tileset definition to avoid renumbering tiles when image width changed · Issue #2863 · mapeditor/tiled · GitHub, since it provides an alternative way for libraries to support Tiled files without needing to replicate the tile cutting logic (so additional parameters don’t complicate the loader).

1 Like

I support the idea of the Spritesheet type tilesets being the catch-all for unusual tilesets of all sorts, even if it’s something as “simple” as having the margin on the right side but not the left.

Hopefully when this is implemented, it’ll feature a UI for automatically generating tile definitions with a good number of settings to tweak. Margin on all four sides, separate x/y spacing, or maybe even tile padding on all four sides instead of spacing, allow applying the automatic definitions to only a subset of the image…