bevy-playground/src/camera.rs

31 lines
673 B
Rust
Raw Normal View History

use bevy::prelude::*;
use crate::player;
pub struct Camera;
impl Plugin for Camera {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn)
.add_systems(PostUpdate, focus);
}
}
fn spawn(mut commands: Commands) {
let mut bundle = Camera2dBundle::default();
bundle.projection.scale = 0.25;
commands.spawn(bundle);
}
fn focus(
player: Query<&Transform, With<player::Player>>,
mut camera: Query<
&mut Transform,
(With<bevy::render::camera::Camera>, Without<player::Player>),
>,
) {
let ply = player.single();
let mut camt = camera.single_mut();
camt.translation = ply.translation
}