bevy_tilemap icon indicating copy to clipboard operation
bevy_tilemap copied to clipboard

Question: How can I know which position is clicked by the player ?

Open Illthiriel opened this issue 3 years ago • 6 comments

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 !

Illthiriel avatar Jan 14 '21 08:01 Illthiriel

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.

joshuajbouw avatar Jan 14 '21 09:01 joshuajbouw

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.

Illthiriel avatar Jan 14 '21 09:01 Illthiriel

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.

joshuajbouw avatar Jan 14 '21 09:01 joshuajbouw

ok thanks a lot :)

Illthiriel avatar Jan 14 '21 09:01 Illthiriel

If I got some times, I will try to write an helper and MR it

Illthiriel avatar Jan 14 '21 09:01 Illthiriel

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)

iMplode-nZ avatar Mar 22 '21 02:03 iMplode-nZ