尝试使用Libgdx创建一个简单的垂直组

时间:2014-10-23 02:04:17

标签: java libgdx

我尝试使用Libgdx VerticalGroup创建一个简单的按钮和标签垂直列表,并将按钮添加到垂直组。不幸的是,它们似乎堆叠在舞台的左下角而不是垂直方向。有没有人知道为什么会这样?我手动定义了我的TextButton样式,所以我想也许垂直组不知道它们有多高是由于某种原因它只是将它们叠加在一起?我真的不想做一个皮肤,因为似乎没有全面的方法来制作皮肤。我过去曾经尝试过,而且从未轻松过。我想做的就是用一些按钮做一个简单的垂直布局。这是我的代码的要点(我已经尝试了很多不同的选项,但基本上就是这样):

vg = new VerticalGroup();
vg.setFillParent(true);
resumeButton = new TextButton("Resume", buttonStyle64x16);
vg.addActor(resumeButton);
// ...add more buttons...
stage.addActor(vg);

按钮样式def:

buttonStyle64x16 = new TextButton.TextButtonStyle();
buttonStyle64x16.up = new TextureRegionDrawable(Assets.button64x16);
buttonStyle64x16.down = new TextureRegionDrawable(Assets.button64x16_down);
buttonStyle64x16.font = Assets.fontMedium;

1 个答案:

答案 0 :(得分:3)

刚测试了你的代码,我想我会把它显示出来。

使用 VerticalGroup

测试代码
VerticalGroup vg = new VerticalGroup();
vg.setFillParent(true);
TextButton resumeButton = new TextButton("Resume", skinMenuPrincipal);
TextButton resumeButton1 = new TextButton("Resume1", skinMenuPrincipal);
TextButton resumeButton2 = new TextButton("Resume2", skinMenuPrincipal);
vg.addActor(resumeButton);
vg.addActor(resumeButton2);
vg.addActor(resumeButton1);

stage.addActor(vg);

Image

如果是这样,我认为错误就像你说的那样在你的按钮中,另一方面如果你想把一些演员放在别处,你也可以用一个表类来做。

Table.add(actor).row();
Table.add(actor1).row();
Table.add(actor2).row();