We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im using a sound effect to shoot in my game, and the problem is that when I shoot like 45 times the game begins to saturate, and the lag make it unplayable. I checked my code, and the problem is with the sound, without it I can shoot 100 times without problems. What could be the problem ? The sound is 3 seconds long. To play it I have something like this.
let sound;
let Shoots = [];
function preload() {
sound = loadsound("shootSound.mp3);
}
function setup(){
createCanvas(1000, 650);
}
function draw(){
for(shoots of Shoots){
shoots.show();
shoots.move();
}
}
function keyPressed(){
if(keyCode === 32){
Shoots.push(new Bullet());
sound.play();
}
}
Is it a common problem ? Or there is something wrong in my game code ? Thankss
Answers
"Sounds" strange to me too. Perhaps ask them directly: :-??
https://GitHub.com/processing/p5.js-sound/issues
Some observations though: L-)
for (shoots of Shoots) {
loop, the 1st variable (the iterator) represents 1 element of the 2nd variable (the container); so it should have a singular name:for (const shoot of shoots) {
"use strict";
before the 1st statement for all of your ".js" files: https://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_modeYou right, I forgot to declare de shoots in the loop. I will take the other advices ! I tried this :
And the lag still appear when I press any key more than 35 times (average), the numer depend on the computer though. I´ll ask them ! Thanks
https://GitHub.com/processing/p5.js-sound/issues/273
The problem was comented in a older thread
https://github.com/processing/p5.js-sound/issues/88
From what I understood, the problem only occurs in Firefox, and because the thread is old I am not sure if they solved it or not, so I decided to develop the game in chrome, where the problem dont happen. Thanks !
Thxs for opening the tix in github and sharing your solution.
Kf