如何临时删除scene2d中的actor

时间:2017-04-21 18:01:12

标签: libgdx scene2d

public static void showHs(boolean remove){
    if(remove){
        table.getCell(hsLabel).getActor().setVisible(true);
        table.getCell(hsLabel).getActor().setWidth(labelsWidth);
    }else {
        table.getCell(hsLabel).getActor().setVisible(false);
        table.getCell(hsLabel).getActor().setWidth(0);
    }
}

setVisible()不会删除actor - 它仍然需要单元格,如果我使用remove()工作,但永久,不能将actor放在同一个地方。 有没有像Visibility.GONE这样的方法?我在这里搜索并结束了。

2 个答案:

答案 0 :(得分:0)

public static void showHs(boolean remove){
    if(remove){
        table.getCell(hsLabel).getActor().setVisible(true);
        table.getCell(hsLabel).getActor().setWidth(labelsWidth);
        table.getCell(hsLabel).expandX();
    }else {
        table.getCell(hsLabel).getActor().setVisible(false);
        table.getCell(hsLabel).getActor().setWidth(0);
        table.getCell(hsLabel).width(0);
    }
}

通过将0宽度设置为单元格来实现,但也许有正确的方法

答案 1 :(得分:0)

这是一个简单的方法,可以让你的表中的演员设置可见性。你不必将演员的宽度设置为零,以使其“消失”#34;。

包含中的第二个参数是Identity,如果为true,则使用== compare。如果为false,将使用.equals()比较。 如果数组包含值,则返回true;如果数组不包含值,则返回false。

   public static void showHs(boolean visible,Actor yourActor){
        if(table.getChildren().contains(actor,true){
                actor.setVisible(visible);
      }
   }
相关问题