bevy_tilemap
bevy_tilemap copied to clipboard
Question: How can I know which position is clicked by the player ?
It's just a question (but could be turn to be a feature request):
In my game the player can interract with the background. So I need to know which position/tile is clicked. Is there a way in tilemap to give a screen coordinate (or a world coordinate) and get the matching position/tile ?
by the way thanks for this amazing crate !
I have something quite similar for this in the new chunk_auto_spawn
system in chunk.rs
on the branch auto_spawn
here: https://github.com/joshuajbouw/bevy_tilemap/blob/auto_spawn/src/chunk.rs#L476.
What that does is gets the camera's current translation and figures out which chunk the camera is currently directly over. It is actually pretty much similar but you would want to change that code to also deal with which tile it is over.
It isn't something that I can really add because you need transform values that are part of the component bundle which the tilemap doesn't exactly directly know. I think some util functions could help in that regard though.
if the input is a world coordinate, it should be possible to determined the position just by calculation (using the tilemap configuration, tile size especialy) wright ? a means without any tile component access. It seams reasonable to me to let the camera coordinate » world coordinate translation outside of the crate.
I've been thinking about adding helpers to add that functionality for users of the library because I imagine that many will likely be requiring exactly that. Especially for selecting. Just will look weird because you would need to tell the Tilemap its own translation.
ok thanks a lot :)
If I got some times, I will try to write an helper and MR it
I feel like this is really necessary for the library, and I would prefer if it was some sort of built-in thing instead of having to be manually done. (Hexagonal tiles might make this slightly difficult though)