My game has an issue where the quality of the sound effects start out good, then deteriorate as the level goes on. Here is a very short video demonstrating the issue: https://www.youtube.com/watch?v=zdnmOriUJ0Y
I am loading and playing the sounds as instructed in the phaser docs.
In preload: this.load.audio('whoosh1', "assets/sound_effects/whoosh1.mp3") this.load.audio('whoosh2', "assets/sound_effects/whoosh2.mp3") this.load.audio('whoosh3', "assets/sound_effects/whoosh3.mp3")
In the player class constructor: this.whoosh1 = scene.sound.add('whoosh1') this.whoosh2 = scene.sound.add('whoosh2') this.whoosh3 = scene.sound.add('whoosh3') this.whooshes = [this.whoosh1, this.whoosh2, this.whoosh3]
The sound effects are played from my throw method: throw(){ this.weapon = new Weapon(this.scene) // object thrown var whoosh_num = Math.floor(Math.random() * this.whooshes.length) this.whooshes[whoosh_num].play(); }
And the throw method is being called in my player finite state machine (inside the update method):
Secondly, when you play a sound from update, update can call throw multiple times, you use JustDown so it must not happens, but check it so you are sure.
Upon printing the sound and looking under manager -> sounds, I see that it does have a large array of sounds in there. It starts out with about 20-25 (first throw) and after about 1 minute of throwing this number is up to 1500, what does this mean? Is it actually playing 1500 sounds at once at that point?
That is what I was logging to see the above object in my image. The problem appears to go away when I clear that array ( sound_name.manager.sounds = []) before playing the sound. Is it ok to do this?
I am loading a lot of sounds I didn’t tell you about, and I was adding them to the scene in the constructor of the player’s projectile. That was why there were so many in the manager after throwing for a while. I moved the sound.add() statements to the player’s constructor and the issue is resolved. Thanks samme
I am also experiencing sound deterioration over the course of my game, but the sound manager has only grown from 19 to 270 sounds after 15 minutes. Is this likely to be the source of my deterioration?
(It becomes noticeable when that count is about 180, but as they say correlation does not prove causation)
SOLVED
The 270 sounds in the manager certainly did degrade the sound playback…
I found it useful to purge the sound manager as each scene wakes.
My sound count went up and down, but never exceeded 50.
The deterioration is ended and the sounds everywhere are brilliant!
Holy cow , the music (by Noah Jacobson-Carroll) sounds spectacular and subtle!!
this.sound.removeAll() ought to be the right method, but it was not found at runtime.(??!)
So I used dumb brute force -