Lifebar design

Hey there guys,

so I am currently building an ingame HUD with a lifebar and other stuff.
I thought it would be smart to use the progress bar from Lemur to display it.
Updating it shouln’t be a problem in the future since there are the methods setProgressValue/setProgressPercent.
However I am wondering on how resitze this bar. Right now it is in a Container which uses the standard layout. I tried to scale the ProgressBar on it X-Axis but it was not the result i need since it “destroys” the layout from the container. So I am wondering if I am missing something. The code for the lifebar looks like this:

    private Container setupLife() {
        Container lifeHolder = new Container("holder");
        DefaultRangedValueModel model = new DefaultRangedValueModel();
        ProgressBar lifeBar = new ProgressBar(model);
        Label currentLife = new Label(String.valueOf(app.getConfig().getLives()));

        currentLife.setFontSize(60f);
        lifeBar.setProgressPercent(100);
        lifeBar.setLocalScale(10,1,1);

        lifeHolder.addChild(lifeBar, 0);
        lifeHolder.addChild(currentLife, 3);
        return lifeHolder;
    }

I am also aware that the model i am using for the progressBar is currently the default one but it shouldn’t make any difference, atleast for my issue right now. Atleast that is what i think.

Cheers guys

Have you tried using setPreferredSize(...) on lifeHolder? If I remember correctly, the progress bar scales itself to fit the size of the container

As codex says, you can set the preferred size on the container but you can also set the preferred size of the progress bar and the container will size itself up to fit.

2 Likes

Thanks guys, worked perfectly :+1:

2 Likes