gpt4 book ai didi

java - LibGdx:表格显示不正确

转载 作者:行者123 更新时间:2023-11-30 03:07:37 25 4
gpt4 key购买 nike

我在 libgdx 中有一个表,它应该有 6 个按钮,分为 2 行。这是我的代码:

        elementsTable.clear();
String[] colors = new String [6];
colors[0] = "red";
colors[1] = "orange";
colors[2] = "yellow";
colors[3] = "purple";
colors[4] = "blue";
colors[5] = "green";

String category = currentCategory.name();
category = category.substring(0, category.length()-1).toLowerCase(); //removes the last character because otherwise there would be an extra 's'

int count = 0;
for(String color : colors) {
ButtonStyle buttonStyle = new ButtonStyle();
buttonStyle.up = cellsSkin.getDrawable(category + "_" + color);
Button button = new Button(buttonStyle);
button.addListener(toolBoxListener);
button.setName(category + "_" + color);
button.setSize(toolBoxButtonSize, toolBoxButtonSize);
elementsTable.add(button).pad(toolBoxButtonPadding);

count ++;
if (count == Math.ceil((colors.length/2d))) elementsTable.row();
}

这就是馅料。我的按钮有 6 种不同的颜色,因此我使用颜色名称遍历数组以访问皮肤以获取按钮的可绘制对象。这部分似乎有效,因为当我调试并查看表格时,它有 6 个大小合适的按钮。

然后我设置我的 table 的位置和大小并将它添加到舞台上。:

    elementsTable.setSize(toolBoxWidth, 500/(float)(3*toolBoxButtonSize+6*toolBoxButtonPadding)*elementsTable.getHeight());
elementsTable.setPosition(195, 30);
stage.addActor(elementsTable);

舞台有一个正交相机组,应该可以很好地缩小物体。

然而,我得到的是: The layout is screwed up.

另一个奇怪的问题是,当我在 Debug模式下查看表格的高度和宽度时,它显示为 0,即使其中的元素都具有正确的大小。

谁能帮帮我?

如果你对这个问题还有什么疑问,欢迎追问!我试图给出详细的描述,但我很乐意回答你的问题。

最佳答案

看来只是位置。 30 对于 Y 来说太低了:

elementsTable.setPosition(195, 30);

例如尝试 150:

elementsTable.setPosition(195, 150);

请记住,Libgdx(和 OpenGL)使用的坐标系是 Y 向上。

关于java - LibGdx:表格显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21534008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com