2024-07-31 16:39:53 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
use bevy::render::camera::{Camera, ScalingMode};
|
2023-12-23 16:50:08 -06:00
|
|
|
|
2024-07-31 16:39:53 -05:00
|
|
|
// #[derive(Component)]
|
|
|
|
// struct GameCamera;
|
|
|
|
|
|
|
|
pub fn startup(mut commands: Commands, mut ui_scale: ResMut<UiScale>) {
|
|
|
|
let mut bundle = Camera2dBundle::default();
|
|
|
|
bundle.projection = OrthographicProjection {
|
2024-07-31 15:55:17 -05:00
|
|
|
near: f32::MIN,
|
|
|
|
far: f32::MAX,
|
2024-07-31 16:39:53 -05:00
|
|
|
scaling_mode: ScalingMode::FixedVertical(360.0 / 1.),
|
2024-07-31 15:55:17 -05:00
|
|
|
..default()
|
|
|
|
};
|
2024-07-31 16:39:53 -05:00
|
|
|
commands.spawn((bundle, IsDefaultUiCamera));
|
|
|
|
|
|
|
|
ui_scale.0 = 1.;
|
2023-12-20 13:24:16 -06:00
|
|
|
}
|
2023-12-23 16:50:08 -06:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|