xxxxxxxxxx
51
var soundA;
var soundB;
var buttonA;
var buttonB;
function preload() {
soundA = loadSound('0.wav');
soundB = loadSound('1.wav');
}
function setup() {
createCanvas(400, 400);
buttonA = createButton('soundA');
buttonA.position(20, 20);
buttonA.mousePressed(changeSoundA);
buttonB = createButton('soundB');
buttonB.position(120, 20);
buttonB.mousePressed(changeSoundB);
background(220);
}
function draw() {
}
function changeSoundA() {
if (soundA.isPlaying()) {
// .isPlaying() returns a boolean
soundA.stop();
} else {
soundA.play();
background(0, 255, 0);
}
}
function changeSoundB() {
if (soundB.isPlaying()) {
// .isPlaying() returns a boolean
soundB.stop();
} else {
soundB.play();
background(255, 0, 0);
}
}