Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.15 #69

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
20 changes: 11 additions & 9 deletions examples/camera_scaling_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand All @@ -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::<f32>() * 0.3, random::<f32>() * 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.),
));
}
}
}
11 changes: 5 additions & 6 deletions examples/clamped_borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down Expand Up @@ -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::<f32>() * 0.3, random::<f32>() * 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.),
));
}
}
}
11 changes: 5 additions & 6 deletions examples/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand All @@ -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::<f32>() * 0.3, random::<f32>() * 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.),
));
}
}
}
11 changes: 5 additions & 6 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand All @@ -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::<f32>() * 0.3, random::<f32>() * 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.),
));
}
}
}
11 changes: 5 additions & 6 deletions examples/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand All @@ -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::<f32>() * 0.3, random::<f32>() * 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.),
));
}
}
}
Expand Down
35 changes: 15 additions & 20 deletions examples/viewport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::{prelude::*, render::camera::Viewport};
use bevy_pancam::{PanCam, PanCamPlugin};
use rand::prelude::random;

fn main() {
App::new()
Expand All @@ -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 {
Expand All @@ -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.),
));
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<MouseButton>,
Expand Down Expand Up @@ -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
}
Expand Down
Loading