Processing button on/off

If on is true, change the background. But what happens is it flickers - I think it’s because it detects multiple mouseclicks and goes on, off, on, off. How do we avoid this? Do I need a delay term? It works, but I only need it to do one switch from on to off or off to on per click (not multiple).

if (mousePressed & rectOver){
    on = !on;
  }
1 Like

Hi,

When you need to check if the mouse is pressed, I would prefer using the function mousePressed() :

void mousePressed(){
  if(rectOver){
    on = !on;
  }
}
3 Likes

Thanks! Works well now, I just included a void mousePressed term within the class and a void mousePressed term out as well which calls the button’s mousepress function.