Replies: 4 comments
-
I found this and updated it for Bevy 0.10 fn handle_mouse_clicks(
mouse_input: Res<Input<MouseButton>>,
window_query: Query<&Window, With<PrimaryWindow>>,
) {
let win = window_query.get_single().unwrap();
if mouse_input.just_pressed(MouseButton::Left) {
println!("click at {:?}", win.cursor_position());
}
} But this is not going to scale well i.e. I'd need to have one of these per thing that need interaction... i guess OOP has the upper hand with this stuff...? |
Beta Was this translation helpful? Give feedback.
-
You'll need to know all the things that can be interacted with. If you only have "a few" sprites, you can use a query on the sprite and the transform, to get its size and position. Then you can do that comparison in a loop over all those sprites. If you have more than "a few", the recommended way is to keep a quad tree or another spatial data structure, that will let you reduce the amount of comparison you will have to do. Depending on your constraints and what other things you're doing, "a few" could easily be up to a few thousands. It also depends if you're memory or CPU constrained. There is an example |
Beta Was this translation helpful? Give feedback.
-
I've built simple interactive system for sprites: https://github.com/StaffEngineer/velo/blob/b72e12bc079caa68a0bbc11e94cab21bb0b32f4f/src/ui_plugin/systems/interactive_sprites.rs#L16 you can do something similar. |
Beta Was this translation helpful? Give feedback.
-
If you don't want to build your own, you can use bevy_mod_picking with the sprite backend. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So i have a simple game i which things appear on screen and move around and need to be touched or clicked to kill them. I can't seen anything on interaction much in the ref or guide? There is the ButtonBundle which has built in interactions, should i use this for all sprites if i want interactions?
Beta Was this translation helpful? Give feedback.
All reactions