We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do you make an action occur only once a button is released? NOTE: Regards to Cp5 button
boolean on = false; void draw() { if(button.isMousePressed()==true){on = true;} if(on == true && button.isMousePressed() == false){on = false; action();} } void action(){}
mayby it help you
Hi, for a button you can call activateBy(), see example, also documented in button class source code.
import controlP5.*; ControlP5 cp5; void setup() { size(400,400); cp5 = new ControlP5(this); cp5.addButton("button").setSize(100,100).activateBy(ControlP5.RELEASE); } void draw() {} void controlEvent(ControlEvent theEvent) { println("event from ", theEvent.getController().getName()); }
you can also use a Callback to capture events from a controller, like in the example below.
import controlP5.*; ControlP5 cp5; int bg = 0; void setup() { size(400, 400); cp5 = new ControlP5(this); cp5.addButton("button").setSize(100, 100); cp5.addCallback(new CallbackListener() { public void controlEvent(CallbackEvent theEvent) { // see the Callback example for more details switch(theEvent.getAction()) { case(ControlP5.ACTION_RELEASE): println("controller release", theEvent.getController().getName()); bg = int(random(255)); break; case(ControlP5.ACTION_PRESS): println("controller press", theEvent.getController().getName()); break; } } } ); } void draw() { background(bg); }
Answers
mayby it help you
Hi, for a button you can call activateBy(), see example, also documented in button class source code.
you can also use a Callback to capture events from a controller, like in the example below.