bevy_ecs_tilemap icon indicating copy to clipboard operation
bevy_ecs_tilemap copied to clipboard

Tiled: Spacing incorrectly parsed

Open CMorrison82z opened this issue 2 years ago • 15 comments
trafficstars

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 :

  1. Incorrect parsing
  2. Incorrect placement (does not strip of the spacing when placing the entities)

CMorrison82z avatar Oct 28 '23 19:10 CMorrison82z

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?

rparrett avatar Oct 28 '23 19:10 rparrett

Yeah it fixes the indexing, but the result from running Bevy still has spacing

CMorrison82z avatar Oct 28 '23 19:10 CMorrison82z

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.

rparrett avatar Oct 28 '23 20:10 rparrett

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 :/

CMorrison82z avatar Oct 28 '23 20:10 CMorrison82z

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.

rparrett avatar Oct 28 '23 20:10 rparrett

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 :

image

CMorrison82z avatar Oct 28 '23 20:10 CMorrison82z

The parameters of my tileset match the one from the other issue you linked. Does tileset_with_spacing.png appear correct in Bevy ?

CMorrison82z avatar Oct 28 '23 20:10 CMorrison82z

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

image

CMorrison82z avatar Oct 28 '23 21:10 CMorrison82z

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 :

image

CMorrison82z avatar Oct 28 '23 21:10 CMorrison82z

Does tileset_with_spacing.png appear 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.

rparrett avatar Oct 28 '23 22:10 rparrett

You would need to set the offset correctly in from_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."

CMorrison82z avatar Oct 28 '23 22:10 CMorrison82z

Correctly as in zero / not the same as padding.

rparrett avatar Oct 28 '23 22:10 rparrett

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.

rparrett avatar Oct 28 '23 22:10 rparrett

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 ?

CMorrison82z avatar Oct 29 '23 14:10 CMorrison82z

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.

rparrett avatar Oct 30 '23 00:10 rparrett

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.

StarArawn avatar Feb 11 '24 13:02 StarArawn