【问题标题】:Trying to create a simple vertical group with Libgdx尝试使用 Libgdx 创建一个简单的垂直组
【发布时间】:2014-10-23 02:04:17
【问题描述】:

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

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

按钮样式定义:

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

【问题讨论】:

    标签: java libgdx


    【解决方案1】:

    刚刚测试了你的代码,我想我可以按需要展示它。

    使用 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);
    

    如果是这样,我认为错误在于您所说的按钮中,另一方面,如果您想将一些演员放在其他地方,您也可以使用一个表类来做到这一点。

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

    【讨论】:

    • 谢谢,我现在可以使用它了。我在做一些愚蠢的事情——我将按钮添加到舞台,然后我将包含按钮的垂直组添加到舞台,这导致了我猜的一些奇怪的行为。在我看来,UI 是制作游戏中最难的事情。
    猜你喜欢
    • 2022-06-10
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    相关资源
    最近更新 更多