bevy-playground/src/camera.rs

33 lines
920 B
Rust
Raw Normal View History

2024-07-29 14:33:14 -05:00
use bevy::prelude::*;
2024-07-29 16:29:39 -05:00
use bevy::render::camera::Camera;
2024-07-29 16:29:39 -05:00
pub fn startup(mut commands: Commands) {
2024-07-31 15:37:11 -05:00
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
bundle.0.projection = OrthographicProjection {
near: f32::MIN,
far: f32::MAX,
scale: 1.,
..default()
};
// bundle.0.transform.translation.z = f32::MAX;
2024-07-31 15:37:11 -05:00
bundle.0.projection.scale = 1.;
commands.spawn(bundle);
}
2024-07-29 16:29:39 -05:00
#[derive(Component, Debug)]
pub struct Watched;
pub fn update(
watched: Query<&Transform, With<Watched>>,
mut camera: Query<&mut Transform, (With<Camera>, Without<Watched>)>,
2024-07-24 17:03:22 -05:00
) {
2024-07-29 16:29:39 -05:00
if let Ok(mut camera) = camera.get_single_mut() {
if let Ok(watched) = watched.get_single() {
2024-07-29 16:54:43 -05:00
camera.translation.x = watched.translation.x;
camera.translation.y = watched.translation.y;
2024-07-29 16:29:39 -05:00
} else {
camera.translation = Vec3::ZERO;
}
2024-07-24 17:03:22 -05:00
}
}