2

我正在玩 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。

4

1 回答 1

4

它非常清楚的文档 [1]

通常,小部件的大小由其父级设置,并且不能使用 setFillParent。setFillParent 仅在小部件的父级未设置其子级(例如舞台)的大小时为方便起见。

所以,我基本上不应该有sceneBoard.setFillParent(true)。只有根表应填充其父表。

[1] https://github.com/libgdx/libgdx/wiki/Scene2d.ui#stage-setup

于 2014-05-12T23:25:24.190 回答