Skip to content

Commit

Permalink
added link to explanation on soundmixer creation;
Browse files Browse the repository at this point in the history
moved mixer creation in astroblasto to `key_down_event`;
  • Loading branch information
PSteinhaus committed Sep 18, 2021
1 parent ba714e6 commit d46b338
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/05_astroblasto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ impl MainState {
game_over: false,
};

audio::maybe_create_soundmixer(ctx);

Ok(s)
}

Expand Down Expand Up @@ -600,6 +598,9 @@ impl EventHandler<ggez::GameError> for MainState {
_keymod: KeyMods,
_repeat: bool,
) {
// creating the mixer on user interaction might be necessary for web
audio::maybe_create_soundmixer(ctx);

match keycode {
KeyCode::Up => {
self.input.yaxis = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Source {
}

/// This function should be called in one of the interaction event callbacks before any usages of audio
/// Because web.
/// Because web: https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Best_practices
pub fn maybe_create_soundmixer(ctx: &mut Context) {
let mut mixer = ctx.audio_context.mixer.borrow_mut();
if mixer.is_none() {
Expand Down

0 comments on commit d46b338

Please sign in to comment.