Reputation: 17
One question currently I am working on a team size seletion screen, So far I did it with checkboxes for team one is finished. Now next to that I wanted to draw another table with the same stage, I don't want to draw with a new Stage in order to save ressources. So my question is it Possible to draw multible tables with one stage next to each other? This is what I currently tried but it didn't work.
So I tried to give a second Table to the constructor something like:
stage.addActor(table,table2)
which did not work.
My second try was something like
stage.addActor(table);
stage.addActor(table2);
which did not work either.
public class TeamSelectScreen implements Screen {
public SEPGame game;
public SpriteBatch menuBatch;
public AssetManager assetManager;
public Viewport viewport;
public Stage stage;
public MenuScreen menuScreen;
public ButtonGroup<CheckBox> teamSelect;
public CheckBox Tank1;
public CheckBox Tank2;
public CheckBox Tank3;
public CheckBox Tank4;
public CheckBox Tank5;
public TeamSelectScreen(SEPGame game) {
game = new SEPGame();
menuBatch = new SpriteBatch();
assetManager = new AssetManager();
viewport = new FitViewport(SEPGame.WORLD_PIXEL_WIDTH, SEPGame.WORLD_PIXEL_HEIGHT);
menuScreen = new MenuScreen(game);
menuScreen.dispose();
stage = new Stage(viewport, menuBatch);
Gdx.input.setInputProcessor(stage);
assetManager.load(Assetdescriptor.backGround);
assetManager.load(Assetdescriptor.buttonNotePressed);
assetManager.load(Assetdescriptor.buttonPressed);
assetManager.load(Assetdescriptor.skinUI);
assetManager.finishLoading();
}
public void setupScreen() {
TextureAtlas menuUi = assetManager.get(Assetdescriptor.backGround);
Skin uiSkin = assetManager.get(Assetdescriptor.skinUI);
TextureRegion backGroundRegion = menuUi.findRegion(Regionnames.backGround);
Table table = new Table();
Table table2 = new Table();
Label title = new Label("Team Auswahl", uiSkin);
Tank1 = new CheckBox("Tank 1 Player", uiSkin);
Tank2 = new CheckBox("Tank 2 Player", uiSkin);
Tank3 = new CheckBox("Tank 3 Ki", uiSkin);
Tank4 = new CheckBox("Tank 4 Ki", uiSkin);
Tank5 = new CheckBox("Tank 5 Ki", uiSkin);
ChangeListener teamSizeChanger = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
}
};
Tank1.addListener(teamSizeChanger);
Tank2.addListener(teamSizeChanger);
Tank3.addListener(teamSizeChanger);
Tank4.addListener(teamSizeChanger);
Tank5.addListener(teamSizeChanger);
Table checkTable = new Table();
checkTable.defaults().pad(5);
checkTable.add(Tank1).row();
checkTable.add(Tank2).row();
checkTable.add(Tank3).row();
checkTable.add(Tank4).row();
checkTable.add(Tank5).row();
Table checkTable2 = new Table();
Table checkTable3 = new Table();
Table checkTable4 = new Table();
Table checkTable5 = new Table();
// Team 1
table.add(checkTable);
table.padRight(1200);
table.setFillParent(true);
table.pack();
table.setBackground(new TextureRegionDrawable(backGroundRegion));
// Team 2
table2.add(checkTable2);
table2.padRight(1000);
table.setFillParent(true);
table.pack();
// Add 2 Tables?
stage.addActor(table);
stage.addActor(table2);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
menuScreen.dispose();
setupScreen();
stage.draw();
}
}
Upvotes: 2
Views: 254
Reputation: 7111
You're calling table.setFillParent(true)
twice but never table2.setFillParent(true)
.
Another option would be adding a Stack
with fill parent to the stage and then adding the two tables to the stack:
Stack stack = Stack(table, table2)
stack.setFillParent(true)
stage.addActor(stack)
Upvotes: 1