【问题标题】:LibGDX Nesting Tables for gameboard grid用于游戏板网格的 LibGDX 嵌套表
【发布时间】:2014-06-22 09:48:12
【问题描述】:

我正在玩 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);
}

a GridSceneBoard 扩展了 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。

【问题讨论】:

    标签: nested libgdx tablelayout scene2d


    【解决方案1】:

    文档 [1] 非常清楚

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-03-12
      • 2014-02-22
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多