Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

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

Open
Illthiriel opened this issue Jan 14, 2021 · 6 comments
Open
Labels
enhancement New feature or request

Comments

@Illthiriel
Copy link

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 Illthiriel added the enhancement New feature or request label Jan 14, 2021
@joshuajbouw
Copy link
Owner

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.

@Illthiriel
Copy link
Author

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.

@joshuajbouw
Copy link
Owner

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.

@Illthiriel
Copy link
Author

ok thanks a lot :)

@Illthiriel
Copy link
Author

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

@mattdm mattdm mentioned this issue Mar 14, 2021
@entropylost
Copy link

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants