【发布时间】:2016-11-27 05:11:58
【问题描述】:
我有这张桌子:
table.add(image1).size(image1.getWidth(), image1.getHeight());
table.add().size(image1.getWidth(), image1.getHeight()).row();
table.add().size(image1.getWidth(), image1.getHeight());
table.add().size(image1.getWidth(), image1.getHeight());
我希望,当我单击空单元格时,从单元格中删除图像并添加到单击的单元格中。例如,当我单击第三个单元格时,从第一个单元格中删除 image1 并将其添加到第三个单元格。怎么办?
更新 2:
我写了这段代码,但是当我点击 cell1 时,image1 没有添加到表格中并添加到右侧屏幕上,点击 cell0 不起作用。
Group group = new Group();
group.addActor(image1);
group.addActor(image2);
group.addActor(image3);
root.add(group).size(16, 16);
root.add(image4).size(image4.getWidth(), image3.getHeight()).row();
root.add(image5).size(image5.getWidth(), image4.getHeight());
root.add(image6).size(image6.getWidth(), image5.getHeight());
stage.addActor(root);
stage.setDebugAll(true);
root.getChildren().get(1).addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
root.getCells().get(1).clearActor();
root.getCells().get(0).clearActor();
root.getCells().get(0).setActor(image1);
group.clear();
group.addActor(image4);
group.addActor(image2);
group.addActor(image3);
root.getCells().get(1).setActor(group);
return true;
}
});
root.getChildren().get(0).addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
root.getCells().get(0).clearActor();
root.getCells().get(1).clearActor();
root.getCells().get(1).setActor(image4);
group.clear();
group.addActor(image1);
group.addActor(image2);
group.addActor(image3);
root.getCells().get(0).setActor(group);
return true;
}
});
【问题讨论】: