gpt4 book ai didi

java - 删除失败时 Actor 会迷路 -libgdx

转载 作者:行者123 更新时间:2023-11-29 08:53:34 24 4
gpt4 key购买 nike

我正在开发一款 rummikub 游戏,我有一个棋盘,上面有方 block ,并且方 block 上的所有位置都定义为 TileActor。有些瓷砖 Actor 上面有实际的瓷砖,有些是空的。问题是:当我将一个图 block 拖放到一个空的 TileActor 上时,它工作正常,但是当我将它放到空白处时, Actor 就会迷路。如何防止 Actor 迷路?

这是我的拖放代码:

dragAndDrop.addSource(new Source(actor) {   
@Override
public Payload dragStart(InputEvent event, float x, float y, int pointer) {
Payload payload = new Payload();
payload.setObject("Some payload!");
payload.setDragActor(getActor());

Label validLabel = new Label("Valid move!", skin);
validLabel.setColor(0, 1, 0, 1);
payload.setValidDragActor(validLabel);

Label invalidLabel = new Label("Invalid!", skin);
invalidLabel.setColor(1, 0, 0, 1);
payload.setInvalidDragActor(invalidLabel);


return payload;
}

dragAndDrop.addTarget(new Target(actor) {
public boolean drag (Source source, Payload payload, float x, float y, int pointer) {
getActor().setColor(Color.GREEN);
return true;
}

public void reset (Source source, Payload payload) {
getActor().setColor(Color.WHITE);
}

public void drop (Source source, Payload payload, float x, float y, int pointer) {

int movingTile =((TileActor)source.getActor()).getPosition();
if(movingTile!=-1){
int newPosition=player.moveTileOnBoard(movingTile, ((TileActor)getActor()).getPosition());

}
}
});

最佳答案

问题是您向 Payload 提供了自己的 Actor(因此 DragAndDrop 需要注意删除这个 actor):

payload.setDragActor(getActor());

尝试创建 Actor 的副本:

Actor newActor = /* clone your actor from getActor() to newActor */;
payload.setDragActor(newActor);

关于java - 删除失败时 Actor 会迷路 -libgdx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21523764/

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