How to create a single sequence of events during draw()

Hey, so I'm making a simple version of photoshop, and I have a menu screen that pops up first.

I recently realized I will have to run draw() while my event sequence is running, else the screen will stay blank.

I tried using Runnable to just execute 2 events alongside draw(), but I couldn't get anything working. Is there an easy way to force the screen to draw but not loop?



  • To clarify, draw() draws the frame after every completion, so if I try to make it wait for a click, draw a new window, new buttons, etc. it'll only draw anything after the thread ends

  • edited August 2015
    • Unless noLoop() is active, Processing's "Animation" Thread calls back draw() at about 60 FPS (or frameRate() FPS) by default.
    • However, when that Thread is busy rendering the canvas, we should not write anything to it!
    • Therefore when we multi-thread, we can write to PImage & PGraphics objects.
    • However we should leave the displaying of them w/ the "Animation" Thread inside draw().
    • We can even use the noLoop() + redraw() approach for it if we want more control of the rendering.
  • Ok so say I have a menu screen which waits for a click before proceeding.


    void setup(){ size(500,700); fill(0); drawMenu(width/2,height/2,"Welcome"); drawButtons(buttons); Click clk = waitForClick(); } void draw(){ }

    doesn't work because draw doesn't actually execute.

    It also doesn't work if you put all that into draw(). How do I circumvent this?

  • Answer ✓

    You need to have your sketch use different states:

    int state, time;
    void setup() {
      size(400, 400);
      state = 0;
      time = millis() + 5000;
    void draw() {
      switch(state) {
      case 0: // Splash screen.
        text("State 0", 20, 20);
        text("I AM A SPLASH SCREEN!\nPlease wait 5 seconds.", 200, 200);
        if (millis() > time ) {
          state = 1;
      case 1:
        background(64, 0, 0);
        fill(255, 0, 255);
        text("State 1", 20, 20);
      case 2:
        background(0, 64, 128);
        fill(0, 255, 255);
        text("State 2", 20, 20);
    void mousePressed() {
      if (state == 1) {
        state = 2;
      if (state == 2 ) {
        state = 1;
Sign In or Register to comment.