我正在玩 LibGDX 并尝试设置一个简单的棋盘游戏。
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);
}
aGridSceneBoard
扩展了 Table 以方便地制作像棋盘一样的图像网格。渲染方法如下:
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();
}
我想嵌套表格以获得更好的 UI 布局(最终),但是当我运行代码时,我得到:
我已经阅读了 TableLayout 的文档以及 LibGDX 的 scene2d.ui 文档,我做错了什么?我正在使用 LibGDX 1.0。