Having a ControlP5 controller inside a class?
in
Contributed Library Questions
•
10 months ago
Hello,
Is it possible to have a controlP5 controller as a property of an object? I'd like to be able to create a number of objects and control their parameters without having to manually create each slider for each object as that gets unwieldy quickly!
Here's an example of what I mean:
- class MyClass{
- float theValue;
- float xpos, ypos;
- MyClass(float XPOS, float YPOS){
- cp5.addSlider("theValue").setRange(0, 255).setValue(127).linebreak();
- xpos= XPOS;
- ypos=YPOS;
- }
- void display(){
- fill(theValue);
- rect(xpos, ypos, 150, 150);
- }
- }
I'm also not quite sure whether the class should have it's own controlEvent method- I assume so, as I can't see any other way to do it without duplicating the code for each object (which is what I'm trying to avoid).
Any pointers appreciated.
1