Problem with tile Z indexes
Hello! I'm working with the Y-Sorting feature in a top-down 2D game.
I found a basic solution for Y-sorting entities somewhere here in the issues, and after some adjustments, I was able to implement it successfully. The main idea is to adjust an entity’s Z translation based on its Y position (plus some other parameters).
Now I'm trying to apply the same logic to specific tiles, which I’m identifying using tile custom metadata. The idea is the same: I want to adjust a tile's Z translation to match the base level of entity Z translation — that way, sorting between entities and these tiles should work correctly.
The problem: When I move tiles in a layer using translation, the Bevy entity moves, but the tile’s visuals do not.
How does this work under the hood? Is it possible to move the visuals of a specific tile (e.g., change its Z index by +97)?
Or maybe there’s a better approach to this?
Also a question: I checked the tile entities spawned by bevy_ecs_ldtk, but I couldn’t find any component that directly holds the tile visuals. The metadata and parameters are there, but no actual sprite or visual component. Where are the tile visuals stored and how can they be manipulated?
Thanks!
bevy_ecs_ldtk uses bevy_ecs_tilemap for rendering tilemaps, and after a little bit of testing, I can't see any way of doing it. It looks like this sort of thing has been brought up before, but perhaps never implemented:
https://github.com/StarArawn/bevy_ecs_tilemap/issues/307
https://github.com/StarArawn/bevy_ecs_tilemap/issues/533
Perhaps @ChristopherBiscardi could offer more insight here
a tilemap is rendered by chunking together a bunch of tiles into a single render mesh, so you won't be able to "move a tile" like that out of the middle of a chunk.
You can do this sort of thing by taking advantage of the depth buffer and some custom shader logic to decide which pixels should be in front of others, but I don't have an example on hand and bevy_ecs_tilemap hasn't implemented built-in depth buffer based sorting after bevy upstreamed support for it in the 2d pipeline.