简体   繁体   中英

Scene2d progress bar not resizing

I added a progress bar to my stage, and it gets a default width as expected. However, I do want to change the width a bit, but for some reason LibGDX don't. I've tried setSize, setWidth, setMinWidth at the background of the progress bar and changing the texture. Nothing works. The only thing I can get to change size of, is the knob.

Here's the code:

background = new Texture("progress_bar_texture");
knob = new Texture("knob_texture");

ProgressBar.ProgressBarStyle pbs = new ProgressBar.ProgressBarStyle();
pbs.background = new TextureRegionDrawable(new TextureRegion(background));       
pbs.knob = new TextureRegionDrawable(new TextureRegion(knob));
pbs.knobAfter = pbs.knob;

progressBar = new ProgressBar(0f, 80f, 1f, false, pbs);
progressBar.setWidth(400); // This doesn't change anything at all...

table.add(progressBar).right().colspan(1).expandX().padRight(40);

Anton, you can increase the width of the ProgressBar within the table using 1. .colspan(2) or 2.Table.setWidth(). If you want precise (pixel-perfect) control of the position and size of the ProgressBar, add it to a Group instead of Table - then the things you tried ( setSize, setWidth, setMinWidth at the background of the progress bar) will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM