Skip to content

Add support for Bevy 0.15 #10

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_core_pipeline",
"bevy_sprite",
] }

[dev-dependencies]
bevy = { git = "https://github.com/bevyengine/bevy" }
bevy = "0.15.0"

[lints]
rust.missing_docs = "warn"
23 changes: 10 additions & 13 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a 2d camera with the PixelCamera bundle in order to
// turn it into a smooth pixel perfect camera.
commands.spawn((
Camera2dBundle::default(),
Camera2d,
Msaa::Off,
PixelCamera::from_size(ViewportSize::PixelFixed(32)),
));

// Spawn a checkerboard background
commands.spawn(SpriteBundle {
texture: asset_server.load("checkerboard.png"),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
});
commands.spawn((
Sprite::from_image(asset_server.load("checkerboard.png")),
Transform::from_xyz(0.0, 0.0, 0.0),
));
// Spawn a bevy icon sprite and mark it with the `BevyIcon` component
commands.spawn((
SpriteBundle {
texture: asset_server.load("bevy_pixel_dark.png"),
transform: Transform::from_xyz(0.0, 0.0, 1.0),
..default()
},
Sprite::from_image(asset_server.load("bevy_pixel_dark.png")),
Transform::from_xyz(0.0, 0.0, 1.0),
BevyIcon,
));
}
Expand All @@ -54,10 +51,10 @@ fn update(
// Get the camera and move it horizontally over time
let mut camera = camera.single_mut();

camera.subpixel_pos.x = (time.elapsed_seconds() / 2.0).sin() * 10.0;
camera.subpixel_pos.x = (time.elapsed_secs() / 2.0).sin() * 10.0;

// Get the bevy icon and move it vertically over time
let mut bevy_transform = bevy.single_mut();

bevy_transform.translation.y = time.elapsed_seconds().sin() * 4.5;
bevy_transform.translation.y = time.elapsed_secs().sin() * 4.5;
}
23 changes: 10 additions & 13 deletions examples/basic_no_smoothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a 2d camera with the PixelCamera bundle in order to
// turn it into a smooth pixel perfect camera.
commands.spawn((
Camera2dBundle::default(),
Camera2d,
Msaa::Off,
PixelCamera {
viewport_size: ViewportSize::PixelFixed(32),
smoothing: false,
Expand All @@ -36,18 +37,14 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
));

// Spawn a checkerboard background
commands.spawn(SpriteBundle {
texture: asset_server.load("checkerboard.png"),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
});
commands.spawn((
Sprite::from_image(asset_server.load("checkerboard.png")),
Transform::from_xyz(0.0, 0.0, 0.0),
));
// Spawn a bevy icon sprite and mark it with the `BevyIcon` component
commands.spawn((
SpriteBundle {
texture: asset_server.load("bevy_pixel_dark.png"),
transform: Transform::from_xyz(0.0, 0.0, 1.0),
..default()
},
Sprite::from_image(asset_server.load("bevy_pixel_dark.png")),
Transform::from_xyz(0.0, 0.0, 1.0),
BevyIcon,
));
}
Expand All @@ -60,10 +57,10 @@ fn update(
// Get the camera and move it horizontally over time
let mut camera = camera.single_mut();

camera.subpixel_pos.x = (time.elapsed_seconds() / 2.0).sin() * 10.0;
camera.subpixel_pos.x = (time.elapsed_secs() / 2.0).sin() * 10.0;

// Get the bevy icon and move it vertically over time
let mut bevy_transform = bevy.single_mut();

bevy_transform.translation.y = time.elapsed_seconds().sin() * 4.5;
bevy_transform.translation.y = time.elapsed_secs().sin() * 4.5;
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Plugin for PixelCameraPlugin {
fn build(&self, app: &mut App) {
use systems::*;

app.insert_resource(Msaa::Off).add_systems(
app.add_systems(
PostUpdate,
(
init_camera.in_set(CameraSystems::Initialization),
Expand Down
46 changes: 20 additions & 26 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,32 @@ pub(crate) fn init_camera(

let viewport_sprite = commands
.spawn((
SpriteBundle {
texture: image_handle,
transform: Transform::from_scale(Vec3::splat(1.0)),
..default()
},
*viewport_layer,
Sprite::from_image(image_handle),
Transform::from_scale(Vec3::splat(1.0)),
viewport_layer.clone(),
PixelViewport,
))
.id();

let viewport_camera = commands
.spawn((
Camera2dBundle {
camera: Camera {
order: *viewport_order,
clear_color: viewport_size.clear_color(),
..default()
},
projection: OrthographicProjection {
far: 1000.,
near: -1000.,
scaling_mode: ScalingMode::Fixed {
width: (size.width - 2) as f32,
height: (size.height - 2) as f32,
},
..default()
},

Camera2d,
Camera {
order: *viewport_order,
clear_color: viewport_size.clear_color(),
..default()
},
OrthographicProjection {
far: 1000.,
near: -1000.,
scaling_mode: ScalingMode::Fixed {
width: (size.width - 2) as f32,
height: (size.height - 2) as f32,
},
..OrthographicProjection::default_2d()
},
ViewportCamera,
*viewport_layer,
viewport_layer.clone(),
))
.id();

Expand Down Expand Up @@ -274,7 +268,7 @@ pub(crate) fn set_camera_position(mut cameras: Query<(&PixelCamera, &mut Transfo
pub(crate) fn smooth_camera(
mut cameras: Query<(&PixelCamera, &PixelViewportReferences)>,
mut viewports: Query<
(&mut Sprite, &Handle<Image>),
&mut Sprite,
(With<PixelViewport>, Without<PixelViewportReferences>),
>,
images: Res<Assets<Image>>,
Expand All @@ -291,8 +285,8 @@ pub(crate) fn smooth_camera(
if !smoothing {
continue;
}
let (mut sprite, handle) = viewports.get_mut(viewport.sprite).unwrap();
let Some(image) = images.get(handle) else {
let mut sprite = viewports.get_mut(viewport.sprite).unwrap();
let Some(image) = images.get(&sprite.image) else {
error!(
"Pixel camera viewport ({:?}) image doesn't exist",
viewport.sprite
Expand Down
Loading