xxxxxxxxxx
22
let kaChing;
function preload() {
kaChing = loadSound('assets/ka-ching.mp3'); // Preload the sound.
}
function setup() {
createCanvas(200, 200); // Set the canvas size.
}
function draw() {
if (kaChing.isPlaying()) {
background(0, 255, 0); // Green while sound is play.
} else {
background(255, 0, 0); // Red while sound is not playing.
}
}
function mousePressed() {
kaChing.play(); // Play sound on mouse click.
}