ControlP5 Button Problem
in
Contributed Library Questions
•
1 year ago
This problem is similar to this:
However, in my case I just want to click a button and show the interface (in the posted code example it just shows the second button), and when the second button is clicked, then to show button1 again. The problem is when the second time you try to click button1. You need to click it twice to work. Why is that??
Any ideas?
- import controlP5.*;
- ControlP5 controlP5;
- Button button1, button2;
- int display = 1;
- void setup() {
- size(600, 480);
- smooth();
- controlP5 = new ControlP5(this);
- controlP5.addButton("button1", 0, 40, 40, 150, 50);
- button1 = (Button) controlP5.controller("button1");
- controlP5.addButton("button2", 1, 40, 140, 150, 50);
- button2 = (Button) controlP5.controller("button2");
- }
- void draw() {
- background(0);
- if (display == 1) {
- button1.show();
- button2.hide();
- }
- else {
- button1.hide();
- button2.show();
- }
- }
- public void button1(int theValue) {
- display = theValue;
- }
- public void button2 (int theValue) {
- display = theValue;
- }
1