首页 文章

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

提问于
浏览
1

我正在尝试使用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 回答

  • 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();
    

相关问题