14

我正在使用 libgdx 游戏框架绘制表格。一切都完美地呈现了我想要实现的目标。我现在需要的只是显示表格的单元格边框,但到目前为止我没有发现任何相关信息。我也倾向于使用调试边框线来完成目的,但也无法改变它们的颜色。

这是我的代码。

Table table = new Table();
table.setFillParent(true);
table.left().top();

table.add(new Label("Results", new LabelStyle(font, Color.BLACK))).colspan(2).expandX();
table.row();
table.add(new Label(text_you_score, new LabelStyle(font, Color.BLACK)));
table.add(new Label(text_actual_score, new LabelStyle(font, Color.BLACK)));
return table;

表格和单元格有许多属性可用,但边框属性不可用。我们也可以手动绘制网格线,但这在我认为的每种设备分辨率上都无法完美运行。任何帮助或想法都非常感谢。谢谢

4

3 回答 3

6

这是基于 libGDX 1.5.3:

一个解决方案是使用NinePatch作为您的Table.

NinePatch patch = new NinePatch(new Texture(Gdx.files.internal("background.png")),
     3, 3, 3, 3);
NinePatchDrawable background = new NinePatchDrawable(patch);

Table table = new Table();
table.setBackground(background);

使用数字变量,您可以修改边界半径。确保这与 png 文件匹配。

于 2015-02-25T20:27:44.967 回答
3
  1. 为调试模式注册您的表

    table.debug();

  2. 调用render()方法

    Table.drawDebug(stage);

例子

于 2013-01-25T11:07:59.957 回答
-1

ShapeRenderer我通过将 a与table.drawDebug(shapeRenderer shapes)调用(我无法开始工作)转换为使用 astage并将表添加为参与者来实现调试行的显示。

上面答案中链接的示例确实清楚地表明了这一点,但这里有一个简短的片段供参考。这是在 libGDX 1.5.3 上。

public class MyGdxGame extends ApplicationAdapter {

    Texture img;
    Stage stage;

    @Override
    public void create () {
        img = new Texture("badlogic.jpg");
        stage = new Stage();
        final Skin skin = new Skin();

        Label.LabelStyle style = new Label.LabelStyle(new BitmapFont(),Color.WHITE);
        TextField.TextFieldStyle textFieldStyle = new TextField.TextFieldStyle();
        textFieldStyle.fontColor = Color.WHITE;
        textFieldStyle.font = new BitmapFont();

        skin.add("default", style);
        skin.add("default", textFieldStyle);
        // Keep your code clean by creating widgets separate from layout.
        Label nameLabel = new Label("Name:", skin);
        TextField nameText = new TextField("",skin);
        Label addressLabel = new Label("Address:", skin);
        TextField addressText = new TextField("",skin);

        Table table = new Table();
        table.add(nameLabel);              // Row 0, column 0.
        table.add(nameText).width(100);    // Row 0, column 1.
        table.row();                       // Move to next row.
        table.add(addressLabel);           // Row 1, column 0.
        table.add(addressText).width(100); // Row 1, column 1.

        table.setOriginX(0);
        table.setOriginY(0);
        table.setX(200);
        table.setY(200);
        table.debug();

        stage.addActor(table);
    }

    @Override
    public void render () {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
    }

    public void resize (int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    public void dispose () {
        stage.dispose();
    }   
}
于 2015-01-30T03:46:49.523 回答