I have a simple game that creates lots of tiny sound effects. It works fine for the first 1 or 2 minutes, but starts rapidly slowing down and lagging soon after. It seems like my computer runs out of RAM? Disabling just the sound effects or simply not triggering them doesn't lag the game at all anymore.
Here's an example of how I would create a sound effect in my game. Is there anything that should be done differently? Or maybe something that clears whatever sound cache is eating up the RAM?
function preload(){
soundFormats("wav","mp3");
sound1 = loadSound("sound1.wav");
}
function setup(){
createCanvas(window.innerWidth, window.innerHeight, WEBGL);
}
var X;
var a = [];
a[0] = "something something 50 something";
a[1] = "something -150 something something";
function soundEffect(value){
X = parseInt(a[value]);
if (X<0) sound1.pan(-0.5);
if (X>0) sound1.pan(0.5);
if (X==0) sound1.pan(0);
sound1.jump(0.06);
sound1.setVolume(0.1);
sound1.play();
}
function mousePressed(){
soundEffect(0);
}
function mouseReleased(){
soundEffect(1);
}
function draw(){
//Game visuals go here
}