Skip to content

Commit

Permalink
Reimplement close_on_esc in breakout example
Browse files Browse the repository at this point in the history
Addresses Bevy #12859 (bevyengine/bevy#12859)
  • Loading branch information
zhaop authored and jakobhellermann committed Aug 11, 2024
1 parent af2b352 commit b864ab3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/bevy_editor_pls/examples/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() {
// `chain`ing systems together runs them in order
.chain(),
)
.add_systems(Update, (update_scoreboard, bevy::window::close_on_esc))
.add_systems(Update, (update_scoreboard, close_on_esc))
.run();
}

Expand Down Expand Up @@ -417,3 +417,19 @@ fn collide_with_side(ball: BoundingCircle, wall: Aabb2d) -> Option<Collision> {

Some(side)
}

fn close_on_esc(
mut commands: Commands,
focused_windows: Query<(Entity, &Window)>,
input: Res<ButtonInput<KeyCode>>,
) {
for (window, focus) in focused_windows.iter() {
if !focus.focused {
continue;
}

if input.just_pressed(KeyCode::Escape) {
commands.entity(window).despawn();
}
}
}

0 comments on commit b864ab3

Please sign in to comment.