bevy-playground/src/camera.rs

35 lines
862 B
Rust
Raw Normal View History

use bevy::prelude::*;
2023-12-25 15:35:10 -06:00
use crate::player::Player;
use bevy::render::camera::Camera as BevyCamera;
pub struct Camera;
impl Plugin for Camera {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn)
2023-12-25 15:35:10 -06:00
.add_systems(PostUpdate, focus)
.add_systems(Update, y_sort);
}
}
fn spawn(mut commands: Commands) {
let mut bundle = Camera2dBundle::default();
2023-12-25 15:22:15 -06:00
bundle.projection.scale = 1. / 2.;
commands.spawn(bundle);
}
fn focus(
2023-12-25 15:35:10 -06:00
player: Query<&Transform, With<Player>>,
mut camera: Query<&mut Transform, (With<BevyCamera>, Without<Player>)>,
) {
2024-02-03 21:15:30 -06:00
let newpos = player.single().translation;
// println!("Cam pos: {newpos}");
camera.single_mut().translation = newpos
2023-12-25 15:35:10 -06:00
}
fn y_sort(mut q: Query<&mut Transform>) {
2024-05-17 09:57:24 -05:00
q.iter_mut()
.for_each(|mut tf| tf.translation.z = -tf.translation.y)
}