我想交换libGDX表中两个标签的位置.我以为我可以使用swapActors来做到这一点,但它没有做到这一点.
private Stage stage;
private Table table;
public MainScreen() {
stage = new Stage(new FitViewport(800, 480));
table = new Table(SkinManagerImpl.getDefaultSkin());
table.add("A").center();
table.add("B").center();
table.setFillParent(true);
boolean succes=table.swapActor(0, 1);
Gdx.app.log("", "success:"+succes);
table.layout();
stage.addActor(table);
}
@Override
public void render(float delta) {
// TODO Auto-generated method stub
super.render(delta);
stage.draw();
}
Run Code Online (Sandbox Code Playgroud)
成功是真的,但它仍然说"AB"而不是"BA".
是否有另一种简单的方法可以在表格内交换两个单元格或演员(意味着交换位置)?
查看 API 文档中的“public Cell getCell(T actor)”方法。
现在看一下 Cell 文档:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Cell.html
您可以获取每个 Cell 实例中的 Actor 实例,然后使用常规的旧交换方法交换它们。使用 Cell.getActor 和 Cell.setActor。十分简单。
| 归档时间: |
|
| 查看次数: |
1435 次 |
| 最近记录: |