Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
630 stars 74 forks source link

Layer transform should not depend of layer's grid size setting? #248

Closed m-jocqueviel closed 8 months ago

m-jocqueviel commented 8 months ago

Hi,

I am buiding a 2d platformer level, but with tiles of different sizes. Basically, I have 16x16 tiles for large scale repetitions, and smaller tiles for details/platforming precision. So I have layer on ldtk with a grid size of 16, and other layers with grid sizes of 8. This is what it looks like in ldtk:

2023-10-17_16-11

But this is what I get in Bevy with the most basic setting in the examples:

2023-10-17_16-13

I checked in the world inspector, and the layer with the 16x16 tiles has a transform of (8, 8), while the other layers have a transform of (4, 4). So I am thinking that maybe computing this offset "per-layer", using the layer's grid size, might not be the best way to go, as it can lead to those kinds of issues?

Trouv commented 8 months ago

Good catch. There is some logic for offsetting the transforms of the layers because bevy_ecs_tilemap anchors tiles at their center, and we need to sort-of cancel this out to support layers of different sizes sitting on top of each other. However, mapping the layer options / tileset options available in LDtk to those available for bevy_ecs_tilemap tilemaps cannot be done perfectly at the moment. I think there's some probably conflating of a layer's grid size vs the source tileset tile size in the transform logic somewhere.

So you have a wall layer with grid size 16 and a detail layer with grid size 8, correct? Are these both sourcing from the same tileset with tile-size 16 in LDtk? Or is the smaller layer sourcing from a different tileset with tile-size 8?

m-jocqueviel commented 8 months ago

Thanks for your answer.

So basically this has been a nightmare to figure out, because I want 16x16 tiles for large tiles area (so I have less repetition), but I still want to have a 8x8 precision when it comes to really designing the level. So I have a 16x16 tileset for the large dark parts, then I have 8x16 and 16x8 tilesets for the edges, and 8x8 for the corners. And after drawing the general shape of the level with my 16x16, I add the smaller tiles with a 8x8 precision this time (and I either add one or two layers of those from my general shape, depending on where exactly I whant my floors/ceilings/walls to be… Not sure if this is clear).

TL;DR: in ldtk I have one layer with a tileset of 16x16, the grid size of the layer is 16. I also have three layers for horizontal/vertical edges, and corners. They are also made of 16x16 tiles, but with some transparent 8x8 sub-tiles, and most importantly the grid size of those layers is 8 (to get some kind of versatile offset, but not really…?).

Without changing anything in bevy_ecs_ldtk, I can simply change my 16x16 layer to make its grid size be 8, and manually place all my 16x16 tiles correctly spaced to get the same result, I just cannot paint anymore, but at least it works.

Sorry if this is all confusing, I know it is very messy!

Trouv commented 8 months ago

Sorry if this is all confusing, I know it is very messy!

It's not your fault it's confusing. I think I understand what you're saying though. To be extra clear, your layer grid sizes are 16 or 8, but the 8-grid-size layers are still using a tileset w/ tile-size 16 correct? It's just that the tiles that the 8-grid-size layers use are half or 3/4 or 1/4 invisible pixels?

Could you see if this PR fixes it? https://github.com/Trouv/bevy_ecs_ldtk/pull/254

m-jocqueviel commented 8 months ago

Yes, I think you exactly described my situation.

And the PR fixed it, everything is alligned, thanks!