単純なオプションは、millis()を使用して手動で時間を追跡することです。
あなたは、2つの変数を使用します。
- 1は、経過時間を格納する
- 1あなたがいるかどうかを確認でしょうdraw()メソッドで
必要待ち時間/遅延時間を格納します現在の時間(ミリ秒)と以前に記憶された時間との間の差は、遅延よりも大きい(または等しい)。
もしそうなら、これは遅延のために与えられたものは何でもして保存時に更新することができているキューになります。
:
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);
}
設定/ニーズに応じて、このようなものを再利用できるクラスにラップすることもできます。これは基本的なアプローチであり、AndroidやJavaScriptのバージョンでも動作するはずです(javascriptではsetInterval()があります)。
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