간단한 옵션은 millis()을 사용하여 수동으로 시간을 추적하는 것입니다.
두 변수를 사용합니다 :
- 일이 경과 된 시간을 저장하는
- 한 당신이 있는지 확인 할 것 무승부() 메소드에서
필요로하는 대기/지연 시간을 저장하는 현재 시간 (밀리 초)과 이전에 저장된 시간 간의 차이가 지연보다 크거나 같아야합니다.
:
int time;
int wait = 1000;
void setup(){
time = millis();//store the current time
}
void draw(){
//check the difference between now and the previously stored time is greater than the wait interval
if(millis() - time >= wait){
println("tick");//if it is, do something
time = millis();//also update the stored time
}
}
여기에 약간의 변화를 업데이트 화면에 '바늘'이다 :
그렇다면, 이것은 당신이있는 거 큐는 지연을 부여하고, 저장 시간을 업데이트 무엇이든 할 것
int time;
int wait = 1000;
boolean tick;
void setup(){
time = millis();//store the current time
smooth();
strokeWeight(3);
}
void draw(){
//check the difference between now and the previously stored time is greater than the wait interval
if(millis() - time >= wait){
tick = !tick;//if it is, do something
time = millis();//also update the stored time
}
//draw a visual cue
background(255);
line(50,10,tick ? 10 : 90,90);
}
설정/필요에 따라 재사용 할 수있는 클래스로이를 포장하도록 선택할 수 있습니다. 이것은 기본 접근 방식이며 자바 스크립트에서 setInterval()을 사용하고 있지만 Android 및 JavaScript 버전에서도 작동해야합니다.
FrankieTheKneeMan이 제안한대로 Java 유틸리티를 사용하고 싶다면 TimerTask 클래스가 있으며 거기에 많은 리소스/예제가 있습니다.
당신은 울부 짖는 데모를 실행할 수 있습니다
var time;
var wait = 1000;
var tick = false;
function setup(){
time = millis();//store the current time
smooth();
strokeWeight(3);
}
function draw(){
//check the difference between now and the previously stored time is greater than the wait interval
if(millis() - time >= wait){
tick = !tick;//if it is, do something
time = millis();//also update the stored time
}
//draw a visual cue
background(255);
line(50,10,tick ? 10 : 90,90);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.4/p5.min.js"></script>
... 어떤 언어를? – FrankieTheKneeMan
나는 처리를 사용하고있다. (Java) – D34thSt4lker