gpt4 book ai didi

java - 如何在 LibGDX scene2d 中让 Actor 暂时移动到前台?

转载 作者:行者123 更新时间:2023-12-01 19:27:47 26 4
gpt4 key购买 nike

我有一个库存 UI,它是 scene2d 中的一个表。然后 table 上有一堆容器,它们基本上是库存槽位。它们具有透明的灰色背景颜色。然后,每个容器中都有一个 ItemStack,其中包含项目的图片和堆栈大小。当我将此 ItemStack 拉到稍后创建的容器上时,它会移动到容器后面,透明的灰色背景将位于项目图片的前面。如何暂时(或永久)将其移动到前台,以便将项目拖动到哪个容器前面都无关紧要?

发生情况的示例: https://i.imgur.com/yq4njex.gifv

这就是我创建容器的方式:

// Create inventory slots
table.row();
inventorySlots.clear();
for (int i = 0; i < inventory.getInventorySize(); i++) {
if (i % SLOTS_PER_ROW == 0) table.row();

Container cont = new Container();
cont.fill();
cont.background(Utils.createDrawable(1, 1, new Color(0, 0, 0, 0.4f)));

inventorySlots.add(cont);
table.add(cont).prefHeight(50).prefWidth(50).pad(5);
}

之后,我将每个 ItemStack 添加到容器/库存槽列表中,如下所示:

// Add ItemStacks from Items to their respective slot
ArrayList<Item> items = inventory.getItems();
for(Container slot : inventorySlots) {
Item item = items.get(inventorySlots.indexOf(slot));

if(item != null) {
ItemStack itemStack = new ItemStack(item);
addInventoryEvent(itemStack, items);
slot.pad(5);
slot.setActor(itemStack);
}
}

最佳答案

您可以使用Actor.setZindex()将您拖动的角色移动到前面。

Sets the z-index of this actor. The z-index is the index into the parent's children, where a lower index is below a higher index. Setting a z-index higher than the number of children will move the child to the front. Setting a z-index less than zero is invalid

解决方案可能是

image.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
image.setZIndex(stage.getActors().size);
return true;
}
});

enter image description here

关于java - 如何在 LibGDX scene2d 中让 Actor 暂时移动到前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60981283/

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