Libgdx Scene2d - 设置演员( TextField )填充?

Libgdx Scene2d - Set actor ( TextField ) padding?(Libgdx Scene2d - 设置演员( TextField )填充?)

本文介绍了Libgdx Scene2d - 设置演员( TextField )填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置填充或类似于演员的东西时遇到了问题.想不通办法.我想我可能必须在皮肤中添加一些东西?

i have been having trouble setting padding or something similar to an actor. Cant figure out the way. I guess that I must add something in the skin maybe?

我有这个文本字段:

        textboxskin = new Skin();
        textboxskin.add("textfieldback", new Texture("data/textfieldback.png"));
        textboxskin.add("cursor", new Texture("data/cursortextfield.png"));
        textboxskin.add("selection", new Texture("data/selection.png"));
        textboxskin.add("font", font);

        TextFieldStyle textfieldstyle = new TextFieldStyle();
        textfieldstyle.background= textboxskin.getDrawable("textfieldback");
        textfieldstyle.disabledFontColor=Color.BLACK;
        textfieldstyle.font=textboxskin.getFont("font");
        textfieldstyle.fontColor=Color.WHITE;
        textfieldstyle.cursor=textboxskin.getDrawable("cursor");
        textfieldstyle.selection=textboxskin.getDrawable("selection");  


        textfieldusername = new TextField("username", textfieldstyle);

看起来像这样:

如您所见,左居中看起来很糟糕......

As you can see it looks horrible left centered...

推荐答案

使用 Table 类来布局 scene2d UI.设置表格:

Use the Table class to lay out scene2d UIs. To set up the Table:

stage = new Stage();
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
table.add(textFieldUsername).padBottom(20f); //also use padTop, padLeft, and padRight
table.row();

在主循环中,调用:

stage.act(Gdx.graphics.getDeltaTime());
stage.draw();

有关表格的详细信息,请参阅:http://code.google.com/p/table-layout/

For more information on tables, see: http://code.google.com/p/table-layout/

这篇关于Libgdx Scene2d - 设置演员( TextField )填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Libgdx Scene2d - 设置演员( TextField )填充?

基础教程推荐