bevy-playground/src/camera.rs

25 lines
666 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-29 14:33:14 -05:00
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
bundle.0.projection.scale = 0.5;
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() {
camera.translation.x = watched.translation.x
} else {
camera.translation = Vec3::ZERO;
}
2024-07-24 17:03:22 -05:00
}
}