Skip to content

Commit

Permalink
migrate examples
Browse files Browse the repository at this point in the history
egui example doesn't show the egui window for some reason. not sure if
that's due to ongoing work on the pr at bevy_egui

also inspector doesn't compile because of the work being done there.

will check back on this when the dust settles a bit
  • Loading branch information
tomara-x committed Nov 15, 2024
1 parent 64dc19d commit 8427200
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 73 deletions.
18 changes: 9 additions & 9 deletions examples/camera_scaling_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
let mut cam = Camera2dBundle::default();
cam.projection.scaling_mode = ScalingMode::FixedVertical(10.0);
let mut ortho = OrthographicProjection::default_2d();
ortho.scaling_mode = ScalingMode::FixedVertical { viewport_height: 10.0 };

commands.spawn((
cam,
Camera2d,
ortho,
PanCam {
min_x: -10.,
max_x: 10.,
Expand All @@ -33,15 +34,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.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/clamped_borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

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.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default(), EguiPlugin))
.add_plugins((DefaultPlugins, PanCamPlugin, EguiPlugin))
.add_systems(Update, egui_ui)
.add_systems(Startup, setup)
.run();
Expand All @@ -33,7 +33,7 @@ fn egui_ui(mut contexts: EguiContexts) {
}

fn setup(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), PanCam::default()));
commands.spawn((Camera2d, PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -44,15 +44,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.),
));
}
}
}
15 changes: 7 additions & 8 deletions examples/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ fn main() {
App::new()
.add_plugins((
DefaultPlugins,
PanCamPlugin::default(),
WorldInspectorPlugin::default(),
PanCamPlugin,
WorldInspectorPlugin::new(),
))
.add_systems(Startup, setup)
.run();
}

fn setup(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), PanCam::default()));
commands.spawn((Camera2d, PanCam::default()));

let n = 20;
let spacing = 50.;
Expand All @@ -26,15 +26,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.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

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.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

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.),
));
}
}
}
13 changes: 6 additions & 7 deletions examples/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.add_systems(Update, toggle_key)
.run();
}

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
37 changes: 16 additions & 21 deletions examples/viewport.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
use bevy::{prelude::*, render::camera::Viewport};
use bevy_pancam::{PanCam, PanCamPlugin};
use rand::prelude::random;

fn main() {
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.add_plugins((DefaultPlugins, PanCamPlugin))
.add_systems(Startup, setup)
.run();
}

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.),
));
}

0 comments on commit 8427200

Please sign in to comment.