+ 2
Why sound is not playing multiple time check line 141 other sound codes on top
The problem is sound is playing after ending but I want to play sound with every fireworks explode https://sololearn.com/compiler-playground/WMacTBEScLTF/?ref=app
4 Respuestas
+ 3
Sword 🪄
maybe this? I applied `ᴴᵗᵗየ 's suggestion and tweaked the object pool implementation.
two sound objects seems to be enough, though. just alternately pop one out, play it, then push it back. Since no sound will be played simultaneously, it shouldn't be a problem just using 2 alternately.
I also ditched the random index scheme for the soundpool because it seemed unnecessary and potentially problematic.
I also renamed this.exploded to this.notExploded because it feels like a more logical name for the particle state.
https://sololearn.com/compiler-playground/WZS8T98NS240/?ref=app
+ 5
Sound is playing every time but with a delay 🤔
Lemme see if I can help you (I don't think I will be able to cuz I have gone rusty will js)
+ 5
Hey Sword 🪄! Add a soundPlayed flag to ensure the sound plays only once per particle explosion. You can do it by applying condition on your explode method.
For your help I do this just replace your explode method with this and it works. Enjoy coding 🤘
explode() {
if (this.exploded) {
sound[Math.floor(Math.random() * sound.length)].src.play();
this.exploded = false; // Ensures sound plays only once
}
this.alpha -= 0.005;
this.x += this.vx;
this.y += this.vy;
this.velocity *= backForce;
this.vy += this.velocity;
this.exploded = false;
}