diff --git a/Cargo.toml b/Cargo.toml index 245d5ba..49a904e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,20 +13,20 @@ version = "0.15.0" bevy_egui = ["dep:bevy_egui"] [dependencies] -bevy = {version = "0.14", features = ["bevy_render"], default-features = false} -bevy_egui = {version = "0.30", optional = true, default-features = false} +bevy = { version = "0.15", features = ["bevy_render", "bevy_window"], default-features = false } +bevy_egui = { version = "0.30", optional = true, default-features = false } [dev-dependencies] -bevy = {version = "0.14", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "bevy_render", "bevy_asset", "bevy_sprite", "bevy_winit", "bevy_core_pipeline", "x11", # github actions runners don't have libxkbcommon installed, so can't use wayland -]} -bevy-inspector-egui = { version = "0.27", default-features = false, features = ["bevy_render"]} -bevy_egui = {version = "0.30", default-features = false, features = ["default_fonts"]} +] } +#bevy-inspector-egui = { version = "0.27", default-features = false, features = ["bevy_render"] } +#bevy_egui = { version = "0.30", default-features = false, features = ["default_fonts"] } rand = "0.8" [[example]] diff --git a/examples/camera_scaling_mode.rs b/examples/camera_scaling_mode.rs index f6a65d7..8a14e0e 100644 --- a/examples/camera_scaling_mode.rs +++ b/examples/camera_scaling_mode.rs @@ -10,11 +10,14 @@ fn main() { } fn setup(mut commands: Commands) { - let mut cam = Camera2dBundle::default(); - cam.projection.scaling_mode = ScalingMode::FixedVertical(10.0); - commands.spawn(( - cam, + Camera2d, + OrthographicProjection { + scaling_mode: ScalingMode::FixedVertical { + viewport_height: 10.0, + }, + ..OrthographicProjection::default_2d() + }, PanCam { min_x: -10., max_x: 10., @@ -33,15 +36,14 @@ fn setup(mut commands: Commands) { let x = x as f32 * spacing + offset; let y = y as f32 * spacing + offset; let color = Color::hsl(240., random::() * 0.3, random::() * 0.3); - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color, custom_size, ..default() }, - transform: Transform::from_xyz(x, y, 0.), - ..default() - }); + Transform::from_xyz(x, y, 0.), + )); } } } diff --git a/examples/clamped_borders.rs b/examples/clamped_borders.rs index c837959..378af28 100644 --- a/examples/clamped_borders.rs +++ b/examples/clamped_borders.rs @@ -11,7 +11,7 @@ fn main() { fn setup(mut commands: Commands) { commands.spawn(( - Camera2dBundle::default(), + Camera2d, PanCam { // prevent the camera from zooming too far out max_scale: 40., @@ -40,15 +40,14 @@ fn setup(mut commands: Commands) { let x = x as f32 * spacing - offset; let y = y as f32 * spacing - offset; let color = Color::hsl(240., random::() * 0.3, random::() * 0.3); - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color, custom_size, ..default() }, - transform: Transform::from_xyz(x, y, 0.), - ..default() - }); + Transform::from_xyz(x, y, 0.), + )); } } } diff --git a/examples/limits.rs b/examples/limits.rs index dab0bbe..12a2174 100644 --- a/examples/limits.rs +++ b/examples/limits.rs @@ -11,7 +11,7 @@ fn main() { fn setup(mut commands: Commands) { commands.spawn(( - Camera2dBundle::default(), + Camera2d, PanCam { // Set max scale in order to prevent the camera from zooming too far out max_scale: 40., @@ -30,15 +30,14 @@ fn setup(mut commands: Commands) { let x = x as f32 * spacing - offset; let y = y as f32 * spacing - offset; let color = Color::hsl(240., random::() * 0.3, random::() * 0.3); - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color, custom_size, ..default() }, - transform: Transform::from_xyz(x, y, 0.), - ..default() - }); + Transform::from_xyz(x, y, 0.), + )); } } } diff --git a/examples/simple.rs b/examples/simple.rs index 9e8f428..c2ffc2a 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -10,7 +10,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn((Camera2dBundle::default(), PanCam::default())); + commands.spawn((Camera2d, PanCam::default())); let n = 20; let spacing = 50.; @@ -21,15 +21,14 @@ fn setup(mut commands: Commands) { let x = x as f32 * spacing - offset; let y = y as f32 * spacing - offset; let color = Color::hsl(240., random::() * 0.3, random::() * 0.3); - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color, custom_size, ..default() }, - transform: Transform::from_xyz(x, y, 0.), - ..default() - }); + Transform::from_xyz(x, y, 0.), + )); } } } diff --git a/examples/toggle.rs b/examples/toggle.rs index 1535c38..4baa709 100644 --- a/examples/toggle.rs +++ b/examples/toggle.rs @@ -11,7 +11,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn((Camera2dBundle::default(), PanCam::default())); + commands.spawn((Camera2d, PanCam::default())); let n = 20; let spacing = 50.; @@ -22,15 +22,14 @@ fn setup(mut commands: Commands) { let x = x as f32 * spacing - offset; let y = y as f32 * spacing - offset; let color = Color::hsl(240., random::() * 0.3, random::() * 0.3); - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color, custom_size, ..default() }, - transform: Transform::from_xyz(x, y, 0.), - ..default() - }); + Transform::from_xyz(x, y, 0.), + )); } } } diff --git a/examples/viewport.rs b/examples/viewport.rs index 67bc206..aa095fa 100644 --- a/examples/viewport.rs +++ b/examples/viewport.rs @@ -1,6 +1,5 @@ use bevy::{prelude::*, render::camera::Viewport}; use bevy_pancam::{PanCam, PanCamPlugin}; -use rand::prelude::random; fn main() { App::new() @@ -11,15 +10,13 @@ fn main() { fn setup(mut commands: Commands) { commands.spawn(( - Camera2dBundle { - camera: Camera { - viewport: Some(Viewport { - physical_position: UVec2::new(100, 200), - physical_size: UVec2::new(600, 400), - depth: 0.0..1.0, - }), - ..Camera2dBundle::default().camera - }, + Camera2d, + Camera { + viewport: Some(Viewport { + physical_position: UVec2::new(100, 200), + physical_size: UVec2::new(600, 400), + depth: 0.0..1.0, + }), ..default() }, PanCam { @@ -32,24 +29,22 @@ fn setup(mut commands: Commands) { )); // background - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color: Color::srgb(0.3, 0.3, 0.3), custom_size: Some(Vec2::new(1000., 1000.)), ..default() }, - transform: Transform::from_xyz(0., 0., 0.), - ..default() - }); + Transform::from_xyz(0., 0., 0.), + )); // red square - commands.spawn(SpriteBundle { - sprite: Sprite { + commands.spawn(( + Sprite { color: Color::srgb(0.8, 0.3, 0.3), custom_size: Some(Vec2::new(100., 100.)), ..default() }, - transform: Transform::from_xyz(0., 0., 1.), - ..default() - }); + Transform::from_xyz(0., 0., 1.), + )); } diff --git a/src/lib.rs b/src/lib.rs index 6fd4af4..f36f906 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -310,7 +310,7 @@ fn do_camera_movement( let direction = pan_cam.move_keys.direction(&keyboard_buttons); let keyboard_delta = - time.delta_seconds() * direction.normalize_or_zero() * pan_cam.speed * projection.scale; + time.delta_secs() * direction.normalize_or_zero() * pan_cam.speed * projection.scale; let delta = mouse_delta - keyboard_delta; if delta == Vec2::ZERO { @@ -330,6 +330,7 @@ fn do_camera_movement( /// A component that adds panning camera controls to an orthographic camera #[derive(Component, Reflect)] #[reflect(Component)] +#[require(Camera2d)] pub struct PanCam { /// The mouse buttons that will be used to drag and pan the camera pub grab_buttons: Vec, @@ -437,7 +438,7 @@ mod tests { /// Simple mock function to construct a square projection from a window size fn mock_proj(window_size: Vec2) -> OrthographicProjection { - let mut proj = Camera2dBundle::default().projection; + let mut proj = OrthographicProjection::default_2d(); proj.update(window_size.x, window_size.y); proj }