简体   繁体   中英

Center libgdx stage object

For a libgdx project, I want to have 3 images at the top centered side by side touching each other, but for some reason the middle one isn't centered and they won't go to the top. They are connected to the button "back" actor.

I tried:

Table table = new Table();
    table.setFillParent(true);
    table.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture("background.png"))));
    table.padTop(50);
    table.add(characters).top().left();
    table.add(items).top();
    table.add(upgrades).top().right();
    table.row();
    table.bottom();
    table.add(back).size(back.getWidth(), back.getHeight()).colspan(2).padBottom(70);
    table.row();
    stage.addActor(table);

If you would illustrate somehow what are you trying to achive and what is your result, it would be easier to answer your question. (It's never too late to do so)

Anyway: You have 3 images and you want them to be on top touching each other.

table.top();
table.add(characters).expandX().padTop(50);
table.add(items).expandX().padTop(50);
table.add(upgrades).expandX().padTop(50);//three images fill up total space given

Should give you the desired layout.

Turning on table.setDebug(true); will help you debugging by drawing debug lines around tables, cells and widgets.

If you are looking for more on topic there is an excellent wiki of Table : https://github.com/libgdx/libgdx/wiki/Table

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