bevy_ecs_tilemap
bevy_ecs_tilemap copied to clipboard
Tiled: Spacing incorrectly parsed
For maps imported from Tiled.
My tileset source image is : columns : 21 tile_size : 16x16 spacing : 1 margin : 0 width : 356 (== 21 * (16 + 1) - 1) -- This may be a source of error. Tilesets with spacing DO NOT have spacing around the far right / bottom tiles (i.e no margin. The size of an edge tile section is just 16, not 17) height : 339 (== 20 * (16 + 1) - 1)
Somehow, tiles are skipped on the far right. For example, the ID of the tile on the 1st column, 2nd row is 21 (when it should be 22. Note that tile indices are shifted by 1 to account for 0 being an empty tile).
I made an attempt at accounting for it and manually modifying the .tmx data, which results in the correct tile texture being used, but there's spacing between adjacent tiles (there should be no spacing in the final product).
As far as I can tell, there are 2 issues :
- Incorrect parsing
- Incorrect placement (does not strip of the spacing when placing the entities)
This sounds like #353 (we just don't support that sort of spacing). If that doesn't sound right, could you provide a tilemap / tileset that demonstrates the problem?
Are you able to work around this by manually adding the "margin" to the tileset texture?
Yeah it fixes the indexing, but the result from running Bevy still has spacing
Just to make sure we're totally on the same page -- I'm suggesting using an image editor to modify the tileset texture to include the same spacing that exists between tiles also around the entire image, not just editing the .tmx.
Yup ! That's what I did
Source image now is 357x340 (1 additional pixel to account for the spacing / margin for right - bottom-most tiles)
Modified the tmx for reflect that change as well. I will try re-exporting it with the new source image to see if it makes a difference !
The problem currently is that the produced map in Bevy has the spacing in it :/
Cool. I wonder if Tiled's "spacing" is on both sides of the tile or something? (i.e. do we need to double it when creating TilemapSpacing in the Tiled helper? Just a quick thought.
I'll try to take a closer look later today.
I wonder if Tiled's "spacing" is on both sides of the tile or something?
No I don't believe so. Source image has 1 pixel spacing, only on the bottom-right of each tile. Importing the tileset to Tiled with width x height = 16 x 16; spacing: 1 and drawing the tiles onto the map in Tiled editor look just fine.
In Bevy, I get :
The parameters of my tileset match the one from the other issue you linked. Does tileset_with_spacing.png appear correct in Bevy ?
I forked and ran the example using the tileset_with_spacing.png (removing the black borders in order to see the render error more clearly). The green squares are squares that I removed the black border from, the blue squares are from the original tiles.png
Note I don't have atlas feature enabled (the tiled_helper seemed to not really support it ? I haven't tried it yet). I see in the .wgsl that spacing considerations are only made for atlas :
Does
tileset_with_spacing.pngappear correct in Bevy ?
It should, yes. You would need to set the offset correctly in from_grid
I see in the .wgsl that spacing considerations are only made for atlas
You probably want to be poking around here or so: https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/src/render/texture_array_cache.rs#L247 where the texture gets chopped up into an array texture.
You would need to set the
offsetcorrectly infrom_grid
That doesn't seem right. "Grid cells are separated by some padding, and the grid starts at offset pixels from the top left corner."
Correctly as in zero / not the same as padding.
Here's a branch that adds a Tiled map with two tilesets:
- One with 1px spacing and 1px margin (first set of tiles displayed)
- One with 1px spacing and 0px margin (second set of tiles displayed)
https://github.com/rparrett/bevy_ecs_tilemap/tree/tiled-padding-test
The first displays correctly. Tiles are the correct size and there is no gap.
The second is messed up -- the transparent padding seems to be included in the "tile area" and the indexing seems potentially messed up.
I think this result is what I would expect, given #353.
The second is messed up -- the transparent padding seems to be included in the "tile area" and the indexing seems potentially messed up.
I think this result is what I would expect, given #353.
If I'm understanding correctly, you're just confirming that results are incorrect for 1px Spacing, 0px Margin ?
If I'm understanding correctly, you're just confirming that results are incorrect for 1px Spacing, 0px Margin ?
Yeah. In other words, I am not seeing an issue beyond #353. If you're seeing otherwise, a reproducer like the one above would be helpful.
I'm not interested in fixing this as this is not a library for loading tiled maps in. The example is only meant to show how one might get started loading tiled maps in and basic usage with bevy_ecs_tilemap.