一个阶段绘制多个表

时间:2019-05-26 17:23:43

标签: java libgdx

我目前正在研究一个团队规模选择屏幕的问题,到目前为止,我已经完成了第一个团队的复选框。现在,接下来,我想绘制另一个具有相同阶段的表,我不想使用新的阶段进行绘制以节省资源。所以我的问题是可以画出一张相邻的多张桌子吗?这是我目前尝试的方法,但是没有用。

因此,我尝试将第二个表提供给构造函数,例如:

stage.addActor(table,table2)

这不起作用。

我的第二次尝试是

stage.addActor(table);
stage.addActor(table2);

这也不起作用。

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();
    }
}

1 个答案:

答案 0 :(得分:1)

您两次致电table.setFillParent(true),但从未致电table2.setFillParent(true)

另一种选择是将具有填充父级的Stack添加到阶段,然后将两个表添加到堆栈中:

Stack stack = Stack(table, table2)
stack.setFillParent(true)
stage.addActor(stack)