簡體   English   中英

嘗試使用Libgdx創建一個簡單的垂直組

[英]Trying to create a simple vertical group with 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;

剛測試了你的代碼,我想我把它顯示為想要的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM