//Sound on off
var song;
function preload() {
song = loadSound('asset/bgm.mp3');
}
function setup() {
var myCanvas = createCanvas(300, 300);
myCanvas.parent('myContainer');
background(255,0,0);
}
function draw() {
background(250,6);
textAlign(CENTER);
noStroke();
textSize(18);
fill(255,200,0);
text("Click Sound start and off",width/2, height/2);
}
function mousePressed() {
if ( song.isPlaying() ) { //isPlaying() returns a boolean
song.stop();
background(255,0,0);
} else {
song.play();
background(0,255,0);
}
}
コメントを残す