I am trying to draw a HUD that shows the score and time and image like loading but I want to update and change the image when the score get higher but I tried to do that but it is not working. I thought maybe I can define new table in the update method and put different image each time but I don't want to define new table each time. is there anyway to update the image only inside the table: this is the code:
public class Hud implements Disposable{
public Stage stage;
private Viewport viewport;
private static Integer worldTimer;
private float timecount;
private static Integer score;
Label countdownLabel;
private static Label scorelabel;
private Label timelabel;
private Label levellabel;
private Label worldlabel;
private Label mariolabel;
private Image loading;
private Table table;
public Hud(SpriteBatch sb)
{
worldTimer=40;
timecount=0;
score=0;
viewport=new FitViewport(Fruits.V_WIDTH,Fruits.V_HIEGT,new OrthographicCamera());//2
stage=new Stage(viewport,sb);//stage is as box and try to put widget and organize things inside that table
table = new Table();
table.top();//table at top of our stage
table.setFillParent(true);//table is now fill all the stage
countdownLabel=new Label(String.format("%02d",worldTimer),new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
scorelabel=new Label(String.format("%02d",score),new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
timelabel=new Label("TIME",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
levellabel=new Label("1-1",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
worldlabel=new Label("WORLD",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
mariolabel=new Label("Score" ,new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
loading = new Image(new Texture("10%.png"));
//loading.setSize(40, 10);
table.add(mariolabel).expandX().padTop(10);
table.add(timelabel).expandX().padTop(10);
table.add(worldlabel).expandX().padTop(10);
table.row();
table.add(scorelabel).expandX();
table.add(countdownLabel).expandX();
table.add(loading).width(50).height(10);
stage.addActor(table);
}
public void update(float dt)
{
timecount+=dt;
if (timecount>1)
{
worldTimer--;
if(worldTimer>=0) {
countdownLabel.setText(String.format("%02d", worldTimer));
loading=new Image(new Texture("90.png"));
}
timecount=0;
}
}
public static int getTime()
{
return worldTimer;
}
public static void addScore(int value)
{
score +=value;
scorelabel.setText(String.format("%02d",score));
}
public static int getScore()
{
return score;
}
@Override
public void dispose() {
stage.dispose();
}
}