Search code examples
processingcontrol-p5

How to hide a text label after mouse is pressed?


I have used Control-P5 library for drawing the text label

  void setup(){
    size(1400,800);
    cp5 = new ControlP5(this);
    myTextlabelB = new Textlabel(cp5,"Hello world",100,100,400,200);
 }

 void draw(){
    myTextlabelB.draw(this); 
    if(mousePressed){ 
        myTextlabelB.hide();
   // I want to hide the label here, but the hide function doesn't work
    }
}

Solution

  • There is some bug with hiding Textlable but it is working with Label class so you just need to get the label part and then hide it:

    myTextlabelB.get().hide();
    

    Also it is important to redraw your background at the beginning of the draw() function

    background(0);