Update screen immediately

Hi everyone! How are you people doing?

I need some help…

I put a button on my script to change some values on screen, but I set framerate to update every second, so every time I click the value take some time to update and thats not practical…Searching a solution I found redraw(); but, it doesn’t seen to be working…Still update every second and not right on click! Any hint How can I take imediate action ignoring the framerate? Thanks in advance!

1 Like

So that’s the minimum delay between each draw() callback.

If you have actions in your sketch which should happen at different delays you’re gonna need to manage that.

You can base that on millis() or frameCount for example.

Or use some library for that. Here’s 1 I’ve made:

1 Like

Maybe try calling draw() instead of redraw().

Thanks guys! sorry for the late response! @rbrauer calling draw(); worked like a charm! Thanks!

I think technically this is a very bad idea

@rbrauer

@rbrauer @edumanilha

Hello,

Can you provide a minimal example? Just for clarity…

An interactive program has the functions setup() and draw() and discussed in the Hello Mouse section:
https://processing.org/tutorials/overview/

Are you doing something different?

:)

Hi! I have a mouseclicked function that add ou subtract time values, I need to update screen when clicked and no the framerate I set (every one second), so I just do what I need (add value to timer) and call the draw to update the screen every time the value changes and not waiting 1 second, that in case is a long time and can generate under or over clicks!..

Hello,

Can you provide a simple code example please?

This may be of interest:
https://processing.org/reference/loop_.html

:)

Try this I think it demonstrates the timing difference. Clicking (redraw()) when the background is red continues through the rest of the red frame, then one green frame, then blue. Keyboard (draw()) when the background is red you get the rest of the red frame then blue.

int tog;

void setup() {
  frameRate(0.5);
}

void draw() {
  background(new int[] {
    color(255, 0, 0), 
    color(0, 255, 0),
    color(0, 0, 255)
  }[tog]);
  tog++;
  tog %= 2;
}

void mouseClicked() {
  tog = 2;
  redraw();
}

void keyPressed() {
  tog = 2;
  draw();
}

Hello @rbrauer

I simplified this:

To this:

  int c3 = 0x00FF0000;
  background( (c3 >>(8*tog)) | 0xFF000000 );

:)