java - Buttons to pause and reset timer -
i add button pauses timer running , button reset timer.
the code below:
import processing.sound.*; void playsoundfile(string filename) { soundfile player; player = new soundfile(this, filename); player.play(); } //load image pimage bg; //store millis function int m = millis(); //also stores millis later use int startingtime; void setup() { size(410,308); //load background image , store in url variable string url = "http://yodas.ws/2007/11/keele1.jpg"; bg = loadimage(url,"jpg"); //stores millis function startingtime = millis(); } void draw() { //sets background image loaded background (bg); //stores second, minute, hour int s = second(); int m = minute(); int h = hour(); //stores , converts second, minute , hour string string sec = str(s); string minu = str(m); string hr = str(h); string time = hr + ":" + minu; //displays time variable text (time, 300, 50); //sets colour of text fill(255,172,108); //sets text size 32 pixels textsize(32); int seconds = (millis() - startingtime) / 1000; //divides seconds 60 minute int minutes = seconds / 60; //divides minutes 60 hour int hours = minutes/60; //multiplies minutes 60 seconds seconds-=minutes * 60; //multiplies hours 60 minutes minutes-=hours * 60; //causes 10 second delay when user presses key if (keypressed == true){ playsoundfile("down.mp3"); delay(10000); } //sets colour of text, displays text , text size fill(255, 0, 0); fill(255,172,108); text((hours) + ":" + (minutes) + ":" + (seconds),20,50); textsize(32); } //void keypressed(){ //if (m < 0){ // delay(1000); // } //} //reset timer //resets timer when user clicks mouse void mouseclicked(){ if (m > 0) { startingtime = millis(); //keypressed(); playsoundfile("down.mp3"); }; };
Comments
Post a Comment