xxxxxxxxxx
27
let sounds = [];
let currentSoundIndex = 0;
function preload() {
for (let i = 0; i<10; i++) {
sounds[i] = loadSound ('drum/' + i +'.mp3');
}
}
function setup() {
createCanvas(400, 400);
console.log(sounds.length);
}
function draw() {
background(220);
}
function mousePressed() {
if (sounds[currentSoundIndex].isPlaying()) {
sounds[currentSoundIndex].pause();
} else {
sounds[currentSoundIndex].play();
currentSoundIndex = (currentSoundIndex + 1) % sounds.length;
}
}