We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
in P3, we have delay()
and exit()
, but didn't find anything similar in p5js reference. What can I do to get the equivalent functions?
Thanks!
Answers
https://Processing.org/reference/frameRate.html
http://p5js.org/reference/#/p5/frameRate
@GoToLoop thanks, now I see remove() can replace exit(); but I still wonder what can perform a sleep or pause effect.
for example, I need some function to replace
delay()
function below in p5js:@GoToLoop thanks, I see what you mean now, but I don't want the whole program to slow down by one frame per second, I only want the 3 second count down to happen before running remove()
@GoToLoop, also I want help about functions in p5js here as I already know how to do it in processing. Thanks
http://studio.ProcessingTogether.com/sp/pad/export/ro.9Djm2xo4wna7I
thanks @GoToLoop, and I googled and it seems that setTimeout() can do the trick
@kennyLiao, actually for a chronometer, setInterval() is even better than setTimeout(): :P
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval
Both of them allow some function or string to be set apart to run "asynchronously".
It's not a real Thread like in Java though. The closer Java Processing got to it is thread() btW:
https://Processing.org/reference/thread_.html
That PJS online example link shows how to accomplish that via frameCount + frameRate().
A much more common practice is use millis(): https://Processing.org/reference/millis_.html
Both of them would work in any Processing flavor modes like: Python, Ruby, PJS, CoffeeScript, etc. O:-)
+1 to using millis. The draw loop is a repeated loop. All you'll achieve with setTimeout/setInterval is creating another separate loop. The only possible advantage is that you can set this to a different rate to the draw loop; but since everything you display is going to be governed by draw you might as well do your time-sensitive events there...
@GoToLoop and @blindfish, I forgot about millis() and it may just do the trick. I will give a try to setInterval too.