How to make a delay in processing project?

試著忘記壹切 提交于 2019-11-28 02:28:39

You should not use delay() or Thread.sleep() in Processing unless you're already using your own threads. Don't use it on the default Processing thread (so don't use it in any of the Processing functions).

Instead, use the frameCount variable or the millis() function to get the time that your event starts, and then check that against the current time to determine when to stop the event.

Here's an example that shows a circle for 5 seconds whenever the user clicks:

int clickTime = 0;
boolean showCircle = false;

void draw(){
  background(64);
  if(showCircle){
    ellipse(width/2, height/2, width, height);

    if(clickTime + 5*1000 < millis()){
      showCircle = false;
    }
  }
}

void mousePressed(){
  clickTime = millis();
  showCircle = true;
}

Side note: please try to use proper punctuation when you type. Right now your question is just one long run-on sentence, which makes it very hard to read.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!