Skip to content

Commit

Permalink
fix: Account for viewport position in sprite backend
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhelsing committed Sep 4, 2024
1 parent 74f0c3c commit 04139be
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backends/bevy_picking_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ pub fn sprite_picking(
continue;
};

let Some(cursor_pos_world) = camera.viewport_to_world_2d(cam_transform, location.position)
let viewport_pos = camera
.logical_viewport_rect()
.map(|v| v.min)
.unwrap_or_default();
let pos_in_viewport = location.position - viewport_pos;

let Some(cursor_pos_world) = camera.viewport_to_world_2d(cam_transform, pos_in_viewport)
else {
continue;
};
Expand Down

0 comments on commit 04139be

Please sign in to comment.