use { bevy::{ prelude::{ default, App, Assets, BuildChildren, Camera2dBundle, Color, Commands, Component, Deref, Handle, PostStartup, Query, Res, ResMut, Resource, SpatialBundle, Startup, Transform, Update, Vec2, Vec3, With, }, sprite::{Sprite, SpriteBundle}, time::Time, DefaultPlugins, }, bevy_oddio::{ builtins::sine::{self, Sine}, output::spatial::SpatialAudioSink, Audio, AudioPlugin, }, oddio::{Sample, Spatial, SpatialOptions}, }; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(AudioPlugin::new()) .add_systems(Startup, init_assets) .add_systems(PostStartup, setup) .add_systems(Update, change_velocity) .run(); } #[derive(Component)] struct Emitter; #[derive(Resource, Deref)] struct SineHandle(Handle); #[derive(Resource)] struct SineSink(Handle>); fn init_assets(mut commands: Commands, mut assets: ResMut>) { let handle = assets.add(Sine); commands.insert_resource(SineHandle(handle)); } fn setup(mut commands: Commands, mut audio: ResMut>, noise: Res) { // Note is in A4. let handle = audio.play_spatial( noise.clone(), sine::Settings::new(0.0, 440.0), SpatialOptions { position: (Vec3::Y * 0.4).into(), velocity: Vec3::ZERO.into(), radius: 0.5, }, ); commands.insert_resource(SineSink(handle)); commands .spawn(SpatialBundle { transform: Transform::from_scale(Vec3::splat(100.0)), ..default() }) .with_children(|parent| { parent .spawn(SpriteBundle { sprite: Sprite { color: Color::GREEN, custom_size: Some(Vec2::new(0.3, 0.3)), ..default() }, transform: Transform::from_xyz(0.0, 0.4, 0.0), ..default() }) .insert(Emitter); }); commands.spawn(Camera2dBundle::default()); } fn change_velocity( sink: Res, mut sinks: ResMut>>, time: Res