We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I'm working with controlP5 and the Icon class which works great except when I turn on "setSwitch(true)". The moment I add this line of code it does not reach the controlEvent function anymore. I've solved it before by checking isPressed on the specific controller and then setting things with iconObject.isOn(), but I've got quite a few more buttons now so I'd love to be able to use the controlEvent function.
Has anyone encountered or fixed this before?
Thanks
Answers
setting the behaviour of an icon to a switch using
setSwitch(true)
, triggers a controlEvent for me, though getting the state of the switch requires to call thegetBooleanValue()
on the controller that triggered the event. To do so you need to cast the Controller linked to the event (theEvent.getController()
) to an Icon which allows you to then call getBooleanValue:another option is to use a CallbackListener
which you can add to an icon with
addCallback(callback)
Thanks for the reply, I'll look into using a callback if I can't get the controlEvent to work. I've looked into it a bit more and found the following: - If I add setSwitch(true) to an icon, the controlEvent still receives it's events - If I then also plug the icon to an object '.plugTo(object)'. The controlEvent inside that object does not receive the events.
Actually, if I have a controlEvent method both inside the object class and in the global scope. The global one is triggered.
plugTo()
looks for members with the same name as given to the Controller but ignorescontrolEvent(ControlEvent)
. In order to trigger the controlEvent your class should implement the ControlListener interface and useaddListener(thing)
instead ofplugTo(thing)
.Ah that makes a lot more sense, I've been using .plugTo(object) and controlEvent in other places to with mixed success so that explains why.
Thanks for these quick answers!