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

I need to hide a shortcut or image temporarily in LibGDX, so I can have part of the button either an image or text depending on the value passed, I 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 completely failed, does anyone know how to do this?

+4
source share
1 answer

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

Something like that ...

 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 screen space, you might want to push them onto the stack.

+5
source

All Articles