一键导入
bevy-audio
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reference for Avian physics engine — rigid bodies, colliders, joints, spatial queries, collision events, character controllers, and debug rendering.
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
Reference for Bevy Scene Notation (BSN) — the bsn! macro for defining inline scenes with components, children, relationships, observers, and dynamic props.
Reference for cameras in Bevy — Camera2d, Camera3d, viewports, projection, render layers, mouse-to-world, and free camera controllers.
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
Reference for bevy_enhanced_input — observer-based input manager with actions, contexts, bindings, conditions, modifiers, presets, and mocking.
| name | bevy-audio |
| description | Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings. |
| metadata | {"crate":"bevy_audio","bevy":"0.19"} |
AudioPlayer<Source> — component to play an audio source (requires PlaybackSettings)AudioSink — component added automatically; controls playback on that entityPitch — asset for generating simple tonesfn play(server: Res<AssetServer>, mut commands: Commands) {
commands.spawn((
AudioPlayer::new(server.load("music.ogg")),
PlaybackSettings::LOOP,
));
}
| Setting | Behavior |
|---|---|
PlaybackSettings::ONCE | Play once |
PlaybackSettings::LOOP | Loop continuously |
PlaybackSettings::DESPAWN | Play once, then despawn entity |
PlaybackSettings::REMOVE | Play once, then remove component |
fn toggle(mut sink: Single<&mut AudioSink, With<MusicBox>>) {
sink.toggle_playback();
}
| Method | Description |
|---|---|
play / pause / stop | Basic playback control. stop cannot restart. |
mute / unmute / toggle_mute | Mute control |
toggle_playback | Toggle play/pause |
speed / set_speed | Playback speed |
empty | True if no more sounds to play |
try_seek | Seek to a position |
volume / set_volume | Volume control |
Global volume via GlobalVolume resource:
app.insert_resource(GlobalVolume::new(Volume::Linear(0.5)));
Per-sink volume:
sink.set_volume(current_volume.increase_by_percentage(10.0));
app.add_plugins(DefaultPlugins.set(AudioPlugin {
default_spatial_scale: SpatialScale::new_2d(1.0 / 100.0),
..default()
}));
Spawn a SpatialListener (only one) for positional audio:
commands.spawn((SpatialListener::new(100.), Transform::default()));
ogg (default), wav, flac, mp3 (enable mp3 feature).
commands.spawn((
AudioPlayer(pitch_assets.add(Pitch::new(220.0, Duration::new(1, 0)))),
PlaybackSettings::DESPAWN,
));