Using Res<Events<CursorMoved>>
I can get the mouse position change in screen space coordinates (zero in bottom-left corner), e.g.
#[derive(Default)]
struct State {
cursor_moved_reader: EventReader<CursorMoved>,
}
fn set_mouse_pos(mut state: ResMut<State>, cursor_moved: Res<Events<CursorMoved>>) {
for event in state.cursor_moved_reader.iter(&cursor_moved) {
println!("cursor: {:?}", event.position);
}
}
The question now is if I set SpriteComponents
' transform.translation
to the cursor position when using a camera from Camera2dComponents::default()
a sprite with position 0, 0
is rendered in the center of the screen. What's the idiomatic way of converting between the screen space mouse coords and the camera world space coords?
camera_x = screen_x/max_screen_x * 2.0 - 1.0
– Santalaceous