xxxxxxxxxx
var song;
var haveWeStarted = false; //false until the user clicks on the project window
var startTime, elapsed, elapsedNoDecimal;
//The preload function is used to load large files, like audio or video
//or really large, high-quality images
function preload() {
song = loadSound("vader.mp3");
}
//Detect when the user has started by clicking on the screen
function mousePressed() {
if (haveWeStarted == false) {
song.amp(0.25); //change to 25% volume
song.play(); //start playing the sound
// song.jump( 10 ); // This fast forwards 10 seconds...useful if you need it
startTime = Date.now();
haveWeStarted = true;
}
}
function setup() {
createCanvas(500, 500);
}
function draw() {
background("black");
if (haveWeStarted == false) {
showStartScreen();
} else {
showAnimation();
}
}
//Only shown at the beginning, this tells the user how to start
function showStartScreen() {
textSize(40);
fill("cyan");
textAlign(CENTER, CENTER);
text("Click to start", width / 2, height / 2);
}
//Put code here to see an animation during the song
function showAnimation() {
elapsed = Date.now() - startTime;
elapsed /= 1000;
elapsedNoDecimal = int(elapsed);
textSize(40);
textAlign(LEFT, BOTTOM);
fill("cyan");
text(elapsed, 0, 40);
}