How to make a wait statement in p5js (if its even possible)

I am working on a code that will be a lot easier if I knew how to make a wait statement. If you know please leave a quick reply.

One thing you do not want to do in p5.js is block the draw function for an extended period of time. However if you want to discontinue all drawing activity for a period of time and then resume from the beginning of your draw function, this is doable:

function draw() {
  background(random(100, 200));
  if (shouldPause) {
    // stop calling draw every frame
    noLoop();
    // Resume calling draw every frame after 5 seconds
    setTimeout(() => loop(), 5000);
    return;
  }
}

This may or may not work for your scenario, we would need to know more about how your sketch works and why you want to “wait” in order to give you a more suitable recommendation.

2 Likes