LoginSignup
0
1

More than 5 years have passed since last update.

ControlP5: ControlEvent handler is called when launching a program / ControlEvent ハンドラがプログラム実行時にも呼ばれてしまう場合

Last updated at Posted at 2019-01-14

結構無駄に長考してしまったのでメモ

例えばボタンを設置するとき,以下のようにするが,その際に初期値の設定などをしようとしてsetValue()など,値が変化する系のメソッドやupdate()系を記述してしまうと,それぞれで一回筒ずつEventが生じてしまう.

button.pde
import controlP5.*;

ControlP5 cp5;
Button button;
int i = 0;

void setup()
{
  size(400,300);
  cp5 = new ControlP5(this);
  button = cp5.addButton("test")
    .setLabel("Label")
    .setPosition(10,10)
    .setSize(40,30)
    .setColorBackground(color(50,50,50))
    .setValue(0)//<------- this invoke an event!!!!!!!
    ;
}

void draw()
{
  background(0);
}

void test()
{
  println("button was pressed (" + i++ + ")");
}
button was pressed (0) //this println() is occured once at least even if the button was not pressed.
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1