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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With