NiklasEi/bevy_kira_audio

Dynamic number of AudioChannels at runtime

Closed this issue · 2 comments

theon commented

Hello, thanks so much for this crate.

I'm currently using 0.9.0 and looking to upgrade to 0.10.0, however in 0.9.0 I'm currently setting a dynamic number of AudioChannels at runtime (use case is using an AudioChannel per enemy so I can set volume per enemy based on distance to the player).

In 0.9.0 this was possible since AudioChannels were keyed by String:

for enemy in enemies {
    channels.insert(
        AudioChannel::new(enemy.id())
    );
}

Is it possible to achieve the same dynamic number of AudioChannels in 0.10.0? Since #44 AudioChannels are resources keyed on a static type; so it seems the number of AudioChannels needs to be fixed at compile-time. I guess I could do something like this with three (or more) volume settings:

    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(AudioPlugin)
        .add_audio_channel::<NearestEnemies>()
        .add_audio_channel::<NearEnemies>()
        .add_audio_channel::<DistantEnemies>()

But it wouldn't give the same granular per-enemy volume control possible in 0.9.0

Looks like there was a lot of work done on this recently in the dynamic_channels branch, but it still targets Bevy 0.7 for now.

theon commented

Thanks so much @NiklasEi! Much appreciated