From b6ba0f2c78b6c4e3e80571723bda8df344abed11 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Mon, 6 Mar 2023 22:43:14 +0000 Subject: [PATCH] Add a new function for getting the handle of a looped sfx track --- src/music_box.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/music_box.rs b/src/music_box.rs index 95bc4ca..ec023cd 100644 --- a/src/music_box.rs +++ b/src/music_box.rs @@ -263,6 +263,25 @@ impl<'w, 's, T: SuppliesAudio> MusicBox<'w, 's, T> { TrackType::Missing => None, } } + + /// Play a new sound effect on the SFX channel in a loop. Ideal for ambient spatial sounds + /// like a crackling fireplace + /// + /// # Returns + /// + /// A handle for the newly started audio instance, or `None` if the track was not found + pub fn start_looped_sfx<Name: ToString>( + &mut self, + name: Name, + ) -> Option<Handle<AudioInstance>> { + match self.map_tracks(name) { + TrackType::WithIntro(_, track) | TrackType::Single(track) => { + let instance = self.channels.sfx_channel.play(track).looped().handle(); + Some(instance) + } + TrackType::Missing => None, + } + } /// Play a new sound effect on the UI SFX channel /// /// # Returns -- GitLab