center camera while zoomed out

This commit is contained in:
Nixon 2022-08-28 17:09:48 +08:00
parent edd3f3a618
commit b08e8efc51
2 changed files with 9 additions and 6 deletions

View file

@ -134,7 +134,7 @@ fn setup(
first_level: Res<FirstLevel>,
mut current_level: ResMut<CurrentLevel>,
mut level_startup_event: EventWriter<LevelStartupEvent>,
mut camera_query: Query<(&mut Transform, &mut OrthographicProjection), With<Camera>>,
mut camera_query: Query<&mut Transform, With<Camera>>,
mut zoom_timer: ResMut<levels::ZoomTimer>,
) {
if current_level.0.is_none() {
@ -582,7 +582,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;
@ -604,7 +608,7 @@ fn level_keyboard_system(
mut commands: Commands,
mut current_level: ResMut<CurrentLevel>,
mut level_startup_event: EventWriter<LevelStartupEvent>,
mut camera_query: Query<(&mut Transform, &mut OrthographicProjection), With<Camera>>,
mut camera_query: Query<&mut Transform, With<Camera>>,
keyboard_input: Res<Input<KeyCode>>,
mut character_list: ResMut<CharacterList>,
level_query: Query<Entity, With<Level>>,

View file

@ -22,12 +22,11 @@ impl Default for ZoomTimer {
pub fn setup_level(
level_startup_event: &mut EventWriter<LevelStartupEvent>,
camera_query: &mut Query<(&mut Transform, &mut OrthographicProjection), With<Camera>>,
camera_query: &mut Query<&mut Transform, With<Camera>>,
zoom_timer: &mut ResMut<ZoomTimer>,
) {
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();