Skip to content

Commit

Permalink
use clear in breakout example
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed May 9, 2022
1 parent 26d880f commit 70a7467
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/games/breakout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,14 @@ fn check_for_collisions(
}

fn play_collision_sound(
mut collision_events: EventReader<CollisionEvent>,
collision_events: EventReader<CollisionEvent>,
audio: Res<Audio>,
sound: Res<CollisionSound>,
) {
// Play a sound once per frame if a collision occurred. `count` consumes the
// events, preventing them from triggering a sound on the next frame.
if collision_events.iter().count() > 0 {
// Play a sound once per frame if a collision occurred.
if !collision_events.is_empty() {
// This prevents events staying active on the next frame.
collision_events.clear();
audio.play(sound.0.clone());
}
}

0 comments on commit 70a7467

Please sign in to comment.