如何延迟处理项目? [英] How to make a delay in processing project?

查看:89
本文介绍了如何延迟处理项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我正在使用java但是我试图做一个不停止程序的延迟但是停止那个代码块的例如,如果我在一个方法中添加1到一个变量我希望它添加1然后等待1秒钟然后再添加1,但延迟()停止整个程序,并在处理项目的Thread.Sleep不工作。

Hi Im using java but Im trying to make a delay that doesn't stop the program but stops that block of code kind of for example if I have it in a method that adds 1 to a variable I want it to add 1 then wait one second then add 1 again but delay() stops the whole program and thread.sleep doesnt work in a processing project.

推荐答案

你不应该在处理中使用 delay() Thread.sleep(),除非你已经在使用你的自己的线程。不要在默认的处理线程上使用它(所以不要在任何处理函数中使用它。)

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).

相反,使用 frameCount 变量或 millis()函数来获取事件开始的时间,然后根据当前时间检查以确定何时停止事件。

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.

这是一个示例,只要用户点击,就会显示一个5秒的圆圈:

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.

这篇关于如何延迟处理项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆