【问题标题】:How to temporary remove actor in scene2d如何在scene2d中临时删除演员
【发布时间】:2017-04-21 18:01:12
【问题描述】:
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() 不会删除演员 - 如果我使用 remove() 作品,它仍然会占用单元格,但永久不能将演员带到同一个地方。 有没有像 Visibility.GONE 这样的方法?我在这里搜索并结束。

【问题讨论】:

    标签: libgdx scene2d


    【解决方案1】:
    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来解决,但也许有正确的方法

    【讨论】:

      【解决方案2】:

      这里有一个简单的方法来让你的演员在你的桌子上设置可见性。您不必将演员的宽度设置为零以使其“消失”。

      contains中的第二个参数是Identity,如果为true,就会使用==比较。如果为 false,将使用 .equals() 比较。 如果数组包含值则为 true,否则为 false。

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

      【讨论】:

        猜你喜欢
        • 2017-04-11
        • 2013-04-23
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        • 1970-01-01
        • 2013-10-04
        • 2016-05-28
        相关资源
        最近更新 更多