cursor ui
This commit is contained in:
+4
-32
@@ -1,14 +1,13 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
mod constants;
|
||||
mod camera;
|
||||
mod citizen;
|
||||
mod game;
|
||||
mod item;
|
||||
mod tile;
|
||||
mod tiles;
|
||||
|
||||
use bevy::color::palettes::basic::WHITE;
|
||||
use game::PIXEL_RATIO;
|
||||
mod cursor;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@@ -25,6 +24,7 @@ fn main() {
|
||||
)
|
||||
.insert_resource(ClearColor(Color::srgb(0.1, 0.1, 0.15)))
|
||||
.add_systems(Startup, (game::setup_level, camera::spawn_panning_camera))
|
||||
.add_systems(Startup, cursor::setup_curor)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
@@ -33,34 +33,6 @@ fn main() {
|
||||
tile::tile_sprite_update,
|
||||
),
|
||||
)
|
||||
.add_systems(FixedUpdate, draw_cursor)
|
||||
.add_systems(FixedUpdate, cursor::move_cursor)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn draw_cursor(
|
||||
camera_query: Single<(&Camera, &GlobalTransform)>,
|
||||
windows: Query<&Window>,
|
||||
mut gizmos: Gizmos,
|
||||
) {
|
||||
let (camera, camera_transform) = *camera_query;
|
||||
|
||||
let Ok(window) = windows.get_single() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(cursor_position) = window.cursor_position() else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Calculate a world position based on the cursor's position.
|
||||
let Ok(point) = camera.viewport_to_world_2d(camera_transform, cursor_position) else {
|
||||
return;
|
||||
};
|
||||
println!(
|
||||
"pos: {}, {}",
|
||||
(point.x / (16. * PIXEL_RATIO)) as i32,
|
||||
(point.y / (16. * PIXEL_RATIO)) as i32
|
||||
);
|
||||
|
||||
gizmos.circle_2d(point, 10., WHITE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user