Support Warning
WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on your configuration, you can check the WebGL2 examples here.
soundtrack.rs:
//! This example illustrates how to load and play different soundtracks,
//! transitioning between them as the game state changes.
use *;
// This resource simulates game states
// This timer simulates game state changes
;
// This resource will hold the track list for your soundtrack
// This component will be attached to an entity to fade the audio in
;
// This component will be attached to an entity to fade the audio out
;
// Every time the GameState resource changes, this system is run to trigger the song change.
// Fade effect duration
const FADE_TIME: f32 = 2.0;
// Fades in the audio of entities that has the FadeIn component. Removes the FadeIn component once
// full volume is reached.
// Fades out the audio of entities that has the FadeOut component. Despawns the entities once audio
// volume reaches zero.
// Every time the timer ends, switches between the "Peaceful" and "Battle" state.