gdo*_*oug 2 nested tablelayout libgdx scene2d
我正在玩 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);
}
Run Code Online (Sandbox Code Playgroud)
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();
}
Run Code Online (Sandbox Code Playgroud)
我想嵌套表格以获得更好的 UI 布局(最终),但是当我运行代码时,我得到:

我已经阅读了 TableLayout 的文档以及 LibGDX 的 scene2d.ui 文档,我做错了什么?我正在使用 LibGDX 1.0。
文档 [1] 非常清楚
通常,小部件的大小由其父级设置,并且不得使用 setFillParent。setFillParent 仅在小部件的父级未设置其子级(例如舞台)的大小时为了方便起见。
所以,我基本上不应该有sceneBoard.setFillParent(true)。只有根表才应填充其父表。
[1] https://github.com/libgdx/libgdx/wiki/Scene2d.ui#stage-setup
| 归档时间: |
|
| 查看次数: |
1957 次 |
| 最近记录: |