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?