In my game I’m using around 60-70 sounds, with maybe a dozen loops in amongst them. As such I thought it would make sense to use an AudioSprite rather than loading dozens of individual files.
Creating the AudioSprite and the JSON is fine, but I’m now discovering you can’t do things like fade the sounds or play multiple markers at once. The only way you can do this, as far as I can determine, is to use multiple addAudioSprite
calls and handle them each separately:
this.musicBG = this.sound.addAudioSprite('sfx', { volume: 0 });
this.musicBG.play('bg_music', { loop: true });
// I can now tween the audiosprite instance
this.tweens.add({
targets: this.musicBG,
volume: 1,
duration: 1000
});
// Create another audio sprite to play sound effects without interrupting the BG music
this.soundFX = this.sound.addAudioSprite('sfx');
this.soundFX.play('yowza');
My question is: is this the way to do it? Is there any performance impact in creating multiple AudioSprites in this way? Almost all of my game sprites are separate prefabs, so they’ll have their own addAudioSprite
/playAudioSprite
calls. I don’t anticipate there being many sounds playing at once - maybe 3-4 at most - but don’t want to cause unnecessary memory issues.