Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to hide a scene widget temporarily in LibGDX

I need to hide a label or an image temporarilly in LibGDX, So I can have part of a button be either an image or text depending on the value passed, I have tried this:

public void SetScore(int score)
{
    if(score<0)
    {
        highScore.setWidth(0);
        lockImage.setWidth(50);
    }
    else
    {
        highScore.setText(Integer.toString(score));
        highScore.validate();
        lockImage.setWidth(0);
    }
}

and it totally failed, does anyone know of how to do this?

like image 564
KatGaea Avatar asked Feb 01 '13 18:02

KatGaea


1 Answers

Assuming that they're standard Scene2d widgets, just use setVisible(true) when you want to see them and setVisible(false) when you don't.

Something along these lines...

public void SetScore(int score)
{
    if(score<0)
    {
        highScore.setVisible(false);
        lockImage.setVisible(true);
    }
    else
    {
        highScore.setVisible(true);
        highScore.setText(Integer.toString(score));
        highScore.validate();
        lockImage.setVisible(false);
    }
}

If they occupy the same space on the screen then you might want to consider putting them on a Stack.

like image 172
Rod Hyde Avatar answered Oct 16 '22 06:10

Rod Hyde