[LibGDX] [solved] Nested Tables Rendering incorrectly

I am attempting to learn the basics of LibGDX by creating a few simple board games. I want to create a basic chess board, and to do so, I am using scene2d and tables. Basically, what I have is a class

GridSceneBoard

that extends

Table

.

The problem I am having is that I want to nest the board into another table. I do so with the following code:


public void show() {
    width       = Gdx.graphics.getWidth();
    height      = Gdx.graphics.getHeight();
    viewport    = new FitViewport(STAGE_WIDTH, STAGE_HEIGHT);
    stage       = new Stage(viewport);
    sceneBoard  = new GridSceneBoard(10, 30, GridBoardCell.Type.CHECKERED);
    rootTable   = new Table();

    rootTable.setFillParent(true);
    sceneBoard.setFillParent(true);

    rootTable.add(sceneBoard);

    stage.addActor(rootTable);
    Gdx.input.setInputProcessor(stage);
}

Both the board and the rootTable have setFillParent set to true. If I directly add the board to the stage, it appears centred on the screen, as I expect.

The render code is as follows:


public void render(float delta) {
    // Set black background.
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // Uncomment for table lines during debugging.
    rootTable.debug();
    sceneBoard.debug();
    Table.drawDebug(stage);

    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}

The result is:

Any suggestions as to what I am doing wrong?

Bump. No love? Does it help if I say that the board is a table of images? :S

[quote]Normally a widget’s size is set by its parent and setFillParent must not be used. setFillParent is for convenience only when the widget’s parent does not set the size of its children (such as the stage).
[/quote]

Can you show the code of your GridSceneBoard. It’s hard to say without knowing how the scene is created.

Try to remove the setFillParent call on the game board. I’m not sure if it was just me beeing dumb, but I didn’t get it to work like that. I only use the setFillParent method on the root table.

Change your add line to this:


rootTable.add(sceneBoard).fill().expand();

The root table will do the layouting for the child table.

Make sure you check out the tutorial on the table layout github page: https://github.com/EsotericSoftware/tablelayout

I had checked this, but apparently had set it in the GridSceneBoard’s constructor as well. Stupid mistake on my part.

Anyways, its solved now, thanks. :slight_smile: