possibly you get a feeling about delay when play this:
/* start from example Basics / Input / Mouse Press. */
boolean usedelay = false;
void setup() {
size(200,200);
background(200,200,0);
println("use key [d] toggle delay 1 sec\nkey [c] clear");
}
void draw() {
if (mousePressed) stroke(255);
else stroke(0);
circle(mouseX,mouseY,20);
if ( usedelay ) delay(1000);
}
void keyPressed() {
if ( key == 'd' ) {
usedelay = ! usedelay;
println("usedelay "+usedelay);
}
if ( key == 'c' ) background(200,200,0); // clear
}
so again, you should not use delay!
but how to delay a action?
for this use must program a timer,
what you can not do as long you get the basic draw loop function wrong.
// add timer
long startT, delayT=5000;
/* start from example Basics / Input / Mouse Press. */
boolean usedelay = false;
void setup() {
size(200,200);
background(200,200,0);
println("use key [d] toggle delay 1 sec\nkey [c] clear");
}
void draw() {
if (mousePressed) stroke(255);
else stroke(0);
circle(mouseX,mouseY,20);
if ( usedelay ) delay(1000);
myTimer();
}
void keyPressed() {
if ( key == 'd' ) {
usedelay = ! usedelay;
println("usedelay "+usedelay);
}
if ( key == 'c' ) background(200,200,0); // clear
}
void myTimer(){
if ( millis() > startT + delayT ) {
startT += delayT; // repeating timer
println(" what happen now? auto clear ");
background(200,200,0);
}
}