Millis() doubt: how to do the program wait two seconds before doing anything?

Hello. I’m new here and I’m trying to make the program wait two seconds before doing anything, but I do not know exactly how to do it. For example, how can I draw a rectangle, then wait two seconds and draw another one, then draw another one two seconds later?

You’re on the right track: you can use the millis() function or the frameCount variable to check how much time has elapsed.

Here’s an example that displays a circle for 60 frames whenever you click the mouse:

int clickedFrame = -999;

void draw(){

  background(0);

  if(frameCount < clickedFrame + 60){
    ellipse(width/2, height/2, width, height);
  }
}

void mousePressed(){
  clickedFrame = frameCount;
}
1 Like

You may try out my “Countdown.java” file: :smiley_cat:

1 Like