From 32c67d46d5612836177d22ef42ded2ab63aec9f3 Mon Sep 17 00:00:00 2001 From: Nixon Date: Sun, 28 Aug 2022 17:09:48 +0800 Subject: [PATCH] center camera while zoomed out --- src/game.rs | 10 +++++++--- src/levels.rs | 5 ++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/game.rs b/src/game.rs index b94eb90..60c1589 100644 --- a/src/game.rs +++ b/src/game.rs @@ -137,7 +137,7 @@ fn setup( first_level: Res, mut current_level: ResMut, mut level_startup_event: EventWriter, - mut camera_query: Query<(&mut Transform, &mut OrthographicProjection), With>, + mut camera_query: Query<&mut Transform, With>, mut zoom_timer: ResMut, ) { if current_level.0.is_none() { @@ -591,7 +591,11 @@ fn camera_system( if zoom_timer.0.finished() { projection.scale = lerp(projection.scale, 1.0, time.delta_seconds() * ZOOM_SPEED); - } else { zoom_timer.0.tick(time.delta()); } + } else { + projection.scale = 3.0; + camera_transform.translation = Vec3::ZERO; + zoom_timer.0.tick(time.delta()); + } // always make sure that camera is away from the object in order to render them camera_transform.translation.z = 999.0; @@ -613,7 +617,7 @@ fn level_keyboard_system( mut commands: Commands, mut current_level: ResMut, mut level_startup_event: EventWriter, - mut camera_query: Query<(&mut Transform, &mut OrthographicProjection), With>, + mut camera_query: Query<&mut Transform, With>, keyboard_input: Res>, mut character_list: ResMut, level_query: Query>, diff --git a/src/levels.rs b/src/levels.rs index 8e5b6b5..0cb284c 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -22,12 +22,11 @@ impl Default for ZoomTimer { pub fn setup_level( level_startup_event: &mut EventWriter, - camera_query: &mut Query<(&mut Transform, &mut OrthographicProjection), With>, + camera_query: &mut Query<&mut Transform, With>, zoom_timer: &mut ResMut, ) { - let (mut transform, mut projection) = camera_query.single_mut(); + let mut transform = camera_query.single_mut(); transform.translation = Default::default(); - projection.scale = 3.0; zoom_timer.0.reset();