You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
//! This example demonstrates how to use the FmodPlugin to play a sound.
|
|
//! Make sure to follow the instructions in the README.md to set up the demo project.
|
|
|
|
use bevy::prelude::*;
|
|
use bevy_fmod::prelude::AudioSource;
|
|
use bevy_fmod::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
FmodPlugin {
|
|
audio_banks_paths: &[
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.bank",
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.strings.bank",
|
|
"./assets/audio/Martian Chess/Build/Desktop/Music.bank",
|
|
],
|
|
},
|
|
))
|
|
.add_systems(Startup, startup)
|
|
.add_systems(PostStartup, play_music)
|
|
.run();
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct MyMusicPlayer;
|
|
|
|
fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
|
|
let event_description = studio.0.get_event("event:/Martian Chess").unwrap();
|
|
|
|
commands
|
|
.spawn(MyMusicPlayer)
|
|
.insert(AudioSource::new(event_description));
|
|
}
|
|
|
|
fn play_music(mut audio_sources: Query<&AudioSource, With<MyMusicPlayer>>) {
|
|
audio_sources.single_mut().play();
|
|
}
|