我正在尝试为我的游戏制作清单,为此我需要制作一个网格。
我正在尝试用桌子完成这件事-
table = new Table();
table.setFillParent(true);
stage.addActor(table);
我应该从这里去哪里?我希望我的网格/库存看起来与此类似 -
在我看来,最好的方法是创建一个 Actor 数组(你可以决定你想要什么样的 Actor,比如你想要一个 Image 按钮等),然后循环遍历数组并将 Actor 添加到表中。
您可以在运行时计算演员的宽度和高度,例如您想填满整个屏幕并且您知道水平和垂直需要多少个按钮,然后:
int actorWidth = Gdx.graphics.getWidth() / rowActors;
int actorHeight = Gdx.graphics.getHeight() / columnActors;
Actor[] actors = new Actor[rowActors * columnActors];
现在用您想要的任何类型的 Actor(图像、按钮等)填充数组并遍历数组并将其添加到表中,如下所示:
for (int i = 0; i < rowActors; i++){
for (int j = 0; j < columnActors; j++){
Actor actor = actors[(i * columnActors) + j];
table.add(actor).width(actorWidth).height(actorHeight);
}
table.row();
}
这应该创建一个占据整个屏幕的演员网格。
这是一个很好的起点,https://github.com/EsotericSoftware/tablelayout。此外,如果您主要使用屏幕资产/像素,您可能希望将场景坐标设置为像素(或者如果您想自动缩放,则设置为像素的固定比率),在您的 resize 方法(缩放 1: 1):
@Override public void resize(int width, int height) {
...
stage.setViewport(width, height,
false, 0, 0, width, height);
}