Skip to content

Commit

Permalink
✨ ambiant music
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienjuif committed Dec 9, 2023
1 parent 73ff91b commit a26ff73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions assets/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
## Audio

- [explosion.ogg](https://freesound.org/people/Werra/sounds/244394/) - edited
- [music.ogg](https://freesound.org/people/ShadyDave/sounds/325647/) - edited
Binary file added assets/sounds/music.ogg
Binary file not shown.
12 changes: 11 additions & 1 deletion src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::prelude::*;
use bevy_cameraman::Cameraman;

const DEBUG: bool = false;
const MUSIC_AUDIO_ID: &str = "sounds/music.ogg";

pub struct AudioPlugin;

Expand All @@ -11,10 +12,19 @@ impl Plugin for AudioPlugin {
}
}

fn setup(mut commands: Commands, query_camera: Query<Entity, With<Cameraman>>) {
fn setup(
mut commands: Commands,
server: Res<AssetServer>,
query_camera: Query<Entity, With<Cameraman>>,
) {
let gap = 200.;
let listener = SpatialListener::new(gap);

commands.spawn(AudioBundle {
source: server.load(MUSIC_AUDIO_ID),
settings: PlaybackSettings::LOOP.with_spatial(false),
});

for entity in &query_camera {
let mut cmd = commands.entity(entity);
let cmd = cmd.insert((SpatialBundle::default(), listener.clone()));
Expand Down

0 comments on commit a26ff73

Please sign in to comment.