Skip to content

Commit

Permalink
fix(scenes): don't throw error when audio cannot be found in cache
Browse files Browse the repository at this point in the history
This happens when the next level starts immediately after the
current audio ends.
  • Loading branch information
remarkablemark committed Feb 12, 2022
1 parent dffb5a2 commit 8956b31
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/scenes/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,18 @@ export default class Main extends Phaser.Scene {
* Plays music.
*/
private playMusic() {
this.music = this.sound.add(this.levelData.music, {
volume: 0.5,
});
this.music.play();
this.music.once('complete', () => {
this.playMusic();
});
try {
this.music = this.sound.add(this.levelData.music, {
volume: 0.5,
});
this.music.play();
this.music.once('complete', () => {
this.playMusic();
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
}

/**
Expand Down

0 comments on commit 8956b31

Please sign in to comment.