Sound plays, but spatial-ness is borked

This commit is contained in:
Daniel Flanagan 2023-12-25 13:29:53 -06:00
parent c54d393d00
commit 7539abb332
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
4 changed files with 29 additions and 6 deletions

7
Cargo.lock generated
View file

@ -1963,6 +1963,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "hound"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
[[package]] [[package]]
name = "image" name = "image"
version = "0.24.7" version = "0.24.7"
@ -2891,6 +2897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1bb7b48ee48471f55da122c0044fcc7600cfcc85db88240b89cb832935e611" checksum = "3b1bb7b48ee48471f55da122c0044fcc7600cfcc85db88240b89cb832935e611"
dependencies = [ dependencies = [
"cpal", "cpal",
"hound",
"lewton", "lewton",
] ]

View file

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bevy = { version = "0.12.1", features = ["wayland"] } bevy = { version = "0.12.1", features = ["wayland", "wav"] }
# bevy = { version = "0.12.1", features = ["wayland", "file_watcher", "trace"] } # bevy = { version = "0.12.1", features = ["wayland", "file_watcher", "trace"] }
[profile.dev] [profile.dev]

View file

@ -1,4 +1,4 @@
use bevy::audio::{AudioPlugin, SpatialScale}; use bevy::audio::{AudioPlugin, SpatialScale, VolumeLevel};
use bevy::prelude::*; use bevy::prelude::*;
mod assets; mod assets;
@ -22,6 +22,7 @@ fn main() {
}) })
.set(AudioPlugin { .set(AudioPlugin {
spatial_scale: SpatialScale::new_2d(100.), spatial_scale: SpatialScale::new_2d(100.),
global_volume: GlobalVolume::new(100.),
..default() ..default()
}) })
.set(ImagePlugin::default_nearest()), .set(ImagePlugin::default_nearest()),

View file

@ -18,7 +18,7 @@ impl Plugin for Player {
} }
fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) { fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
let listener = SpatialListener::new(0.); let listener = SpatialListener::new(1.);
commands commands
.spawn(( .spawn((
@ -40,14 +40,29 @@ fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
} }
fn controls( fn controls(
mut query: Query<(&mut TextureAtlasSprite, &mut Heading), With<Player>>, mut commands: Commands,
mut query: Query<(&mut TextureAtlasSprite, &mut Heading, Entity), With<Player>>,
input: Res<Input<KeyCode>>, input: Res<Input<KeyCode>>,
assets: Res<AssetLoader>,
) { ) {
let (mut sprite, mut heading) = query.single_mut(); let (mut sprite, mut heading, player_entity) = query.single_mut();
**heading = Vec2::ZERO; **heading = Vec2::ZERO;
for key in input.get_just_pressed() {
match key {
KeyCode::Space => {
let child = commands
.spawn(AudioSourceBundle {
source: assets.sounds.meow.clone(),
settings: PlaybackSettings::DESPAWN.with_spatial(true),
})
.id();
commands.entity(player_entity).push_children(&[child]);
}
_ => {}
}
}
for key in input.get_pressed() { for key in input.get_pressed() {
match key { match key {
KeyCode::Space => {}
KeyCode::A | KeyCode::Left => { KeyCode::A | KeyCode::Left => {
**heading -= Vec2::X; **heading -= Vec2::X;
} }