mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 17:18:50 +00:00
Compare commits
2 commits
4e2c18b0c1
...
bc9ea50264
| Author | SHA1 | Date | |
|---|---|---|---|
| bc9ea50264 | |||
| 9777c4b6b4 |
4 changed files with 35 additions and 3 deletions
|
|
@ -16,6 +16,7 @@ comet_ecs = { path = "./crates/comet_ecs", workspace = true }
|
|||
comet_input = { path = "./crates/comet_input", workspace = true }
|
||||
comet_log = { path = "./crates/comet_log", workspace = true }
|
||||
comet_structs = { path = "./crates/comet_structs", workspace = true }
|
||||
comet_sound = { path = "./crates/comet_sound", workspace = true }
|
||||
|
||||
cfg-if = "1"
|
||||
anyhow = "1.0"
|
||||
|
|
@ -62,4 +63,5 @@ comet_resources = { path = "./crates/comet_resources", workspace = true }
|
|||
comet_ecs = { path = "./crates/comet_ecs", workspace = true }
|
||||
comet_input = { path = "./crates/comet_input", workspace = true }
|
||||
comet_log = { path = "./crates/comet_log", workspace = true }
|
||||
comet_structs = { path = "./crates/comet_structs", workspace = true }
|
||||
comet_structs = { path = "./crates/comet_structs", workspace = true }
|
||||
comet_sound = { path = "./crates/comet_sound", workspace = true }
|
||||
|
|
|
|||
|
|
@ -111,6 +111,11 @@ impl App {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_audio(mut self, audio_system: Box<dyn Audio>) -> Self {
|
||||
self.audio = audio_system;
|
||||
self
|
||||
}
|
||||
|
||||
fn load_icon(path: &std::path::Path) -> Option<Icon> {
|
||||
let image = match image::open(path) {
|
||||
Ok(image) => image,
|
||||
|
|
@ -387,8 +392,7 @@ impl App {
|
|||
match renderer.render() {
|
||||
Ok(_) => {}
|
||||
Err(
|
||||
wgpu::SurfaceError::Lost
|
||||
| wgpu::SurfaceError::Outdated,
|
||||
wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated,
|
||||
) => {
|
||||
let size = renderer.size();
|
||||
renderer.resize(size);
|
||||
|
|
|
|||
26
examples/hello_sound.rs
Normal file
26
examples/hello_sound.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use comet::prelude::*;
|
||||
use comet_sound::Audio;
|
||||
|
||||
fn setup(app: &mut App, _renderer: &mut Renderer2D) {
|
||||
app.load_audio("startup", "res/sounds/hit.ogg");
|
||||
app.play_audio("startup", true); // second parameter loops the sound
|
||||
|
||||
// here the float indicated the volume percentage
|
||||
// in the standard backend for audio in comet (kira) 0.0 is equal to -20dB and 1.0 to 0dB
|
||||
app.set_volume("startup", 1.0);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
// in this example, update_audio doesnt do anything because the kira audio system
|
||||
// doesnt need any update
|
||||
app.update_audio(dt);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.with_title("Comet Audio Example")
|
||||
// This can be used to add your own sound engine to the engine
|
||||
.with_audio(Box::new(comet_sound::KiraAudio::new())) // to
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
BIN
res/sounds/hit.ogg
Normal file
BIN
res/sounds/hit.ogg
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue