用于游戏机网格的LibGDX嵌套表 [英] LibGDX Nesting Tables for gameboard grid

查看:119
本文介绍了用于游戏机网格的LibGDX嵌套表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩LibGDX,并试图建立一个简单的棋盘游戏.

I am playing with LibGDX and trying to set up a simple board game.

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,以方便地像棋盘一样制作图像网格.渲染方法如下:

a GridSceneBoard extends a Table to conveniently make a grid of images like a chess board. The render method 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();
}

我想嵌套表格以获得更好的UI布局(最终),但是当我运行代码时,我得到了:

I want to nest the tables for better UI layout (eventually), but when I run the code I get:

我已经阅读了TableLayout的文档以及LibGDX的scene2d.ui文档,我在做什么错呢?我正在使用LibGDX 1.0.

I've read TableLayout's documentation as well as LibGDX's scene2d.ui documentation, what am I doing wrong? I am using LibGDX 1.0.

推荐答案

文档[1]非常清楚

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

Normally a widget's size is set by its parent and setFillParent must not be used. setFillParent is for convenience only when the widget's parent does not set the size of its children (such as the stage).

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

So, I basically should never have sceneBoard.setFillParent(true). Only the root table should fill its parent.

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

这篇关于用于游戏机网格的LibGDX嵌套表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆