pub struct DefaultAudioPlugin;Expand description
Ready-to-use audio plugin that plays SfxRequest and
PitchedSfxRequest messages via Bevy’s built-in bevy_audio backend.
For each incoming request, this plugin:
- Resolves the event key through
SfxConfig::pick_path(round-robin across registered variants). - Loads the asset with
AssetServer::load. - Spawns an
(AudioPlayer, PlaybackSettings::ONCE)entity that Bevy’s audio system plays once. The entity is not despawned when the sound ends. The volume comes fromSfxConfig::volumeand, for aPitchedSfxRequest, the speed comes fromPitchedSfxRequest::effective_pitch.
The plugin also initializes SfxFilter (off by default). While that
filter is on, new sounds are played through a low-pass filter; see
SfxFilter for what is and is not filtered.
§Setup
Register asset paths with SfxConfig before adding the plugin, or
populate them in a startup system:
use bevy::prelude::*;
use voxel_framework::audio::{DefaultAudioPlugin, SfxConfig, SfxEvent, SfxPlugin};
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(SfxPlugin)
.add_plugins(DefaultAudioPlugin)
.add_systems(Startup, |mut cfg: ResMut<SfxConfig>| {
cfg.register(SfxEvent::MiningComplete, vec!["sounds/break.ogg"]);
cfg.register(SfxEvent::BlockPlace, vec!["sounds/place.ogg"]);
})
.run();§Missing files
If an asset path is not found on disk, Bevy logs a warning and skips playback — no panic, no crash.
§Spatial audio
When the SfxRequest::position field is Some, the plugin attaches a
SpatialListener-compatible Transform to the audio entity so Bevy
can attenuate volume by distance. Requires a SpatialListener on the
camera/player entity.
Trait Implementations§
impl DefaultImplementationPlugin for DefaultAudioPlugin
Source§impl Plugin for DefaultAudioPlugin
impl Plugin for DefaultAudioPlugin
Source§fn finish(&self, app: &mut App)
fn finish(&self, app: &mut App)
Registers the low-pass playback path once every plugin is built, so
the order in which this plugin and Bevy’s plugins are added does not
matter. Without Bevy’s audio and asset plugins nothing is registered
and SfxFilter has no effect.
Source§fn ready(&self, _app: &App) -> bool
fn ready(&self, _app: &App) -> bool
finish should be called.Source§fn cleanup(&self, _app: &mut App)
fn cleanup(&self, _app: &mut App)
impl VoxelFrameworkPlugin for DefaultAudioPlugin
Auto Trait Implementations§
impl Forget for DefaultAudioPlugin
impl Freeze for DefaultAudioPlugin
impl Move for DefaultAudioPlugin
impl RefUnwindSafe for DefaultAudioPlugin
impl Send for DefaultAudioPlugin
impl Sync for DefaultAudioPlugin
impl Unpin for DefaultAudioPlugin
impl UnsafeUnpin for DefaultAudioPlugin
impl UnwindSafe for DefaultAudioPlugin
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more