Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Remove objects with many CP5 controllers

$
0
0

Hello, I'm rather new to Processing, so please bear with me. I am writing code to allow me to control multiple servos with two CP5 sliders. I hope to make it variable, allowing for a pair for each servo attached. I have made a class for the slider pairs (SvoPkg), and have no issues using a bang to call them up. However, I'm stuck on how to make them disappear. I'm using an ArrayList to call the object, but remove() will only clear the List, not the objects on screen. Similarly, since the sliders are nested in an object, I can't seem to remove them piecemeal using .getController().remove() either (I get a Static/non-static error). I've tried using the draw() function to add the object to better update the screen when the List is cleared, but that won't work because the sliders aren't usable anymore -the draw loop make them essentially a picture and immobile. I'd like to basically have a remove() function for the object (like CP5 has for its individual controllers), but don't quite know how to implement one.

Here is a dumbed-down version of the code; for clarity's sake I'm just using one Package and have altered the position data. Right now, I'm trying to just use one bang to make the object, and the other to remove it.

    import controlP5.*;
    ControlP5 gui;

    ArrayList<SvoPkg> layout;
    int PkgTot = 1;

    void setup(){
      size (300, 150);
    gui = new ControlP5(this);
      layout = new ArrayList<SvoPkg>();
      fill(230,170,90);

    gui.addBang ("Make")
      .setPosition(200,95)
      .setSize(40,30)
      ;
    gui.addBang ("Kill")
      .setPosition(250,95)
      .setSize(40,30)
      ;
    }
    void draw(){
     background(190,130,30);
        }

    void Make(){
      for(int i=0; i<PkgTot;i++){
          layout.add(new SvoPkg(this, 20, 30));
         }
     }
     void kill(){ //I've left this blank for now, but is where I'd like to remove the object
     }

     class SvoPkg {
      PApplet app;
      ControlP5 Objgui;

    SvoPkg(PApplet papp, float Xpos, float Ypos){
     app = papp;
     Objgui = new ControlP5(papp);

    Objgui.addSlider("Angle")
       .setPosition(Xpos+15, Ypos+ 15)
       .setSize(120, 10)
       .setRange(600,2400)
       ;
    Objgui.addSlider("Speed")
      .setPosition(Xpos+15, Ypos + 30)
      .setSize(120, 10)
      .setRange(50,1000)
      ;
    }
    }

Thanks for your input


Viewing all articles
Browse latest Browse all 2896

Trending Articles