xxxxxxxxxx
33
var kick;
var lastTime;
// We want to repeat the playing of the sound automatically (without re-triggering)
// We already have a loop: the draw loop
// 1. Try playing the drum from the draw loop
// 2. Slow draw loop down with frameRate. Do you anticipate any problems with this?
// 3. Keep frameRate, but use millis() to keep track of time
function preload(){
kick = loadSound('sounds/kick.mp3');
}
function setup() {
createCanvas(600, 400);
background(100, 233, 100);
setInterval(audioLoop, 1000);
}
function draw(){
// Draw ellipses
for(let i = 0; i < 10; i++){
ellipse(random()*width, random()*height, 100, 100);
}
}
// Better, but still not reliable.
function audioLoop(){
kick.play();
}