【问题标题】:libgdx - scene2d.ui label positionlibgdx - scene2d.ui 标签位置
【发布时间】:2014-10-18 20:05:48
【问题描述】:

如何将多行Label 停靠在屏幕底部?有Label.setY() 方法,但它以某种神秘的方式工作,对我来说毫无意义。我可以使用getWrappedBounds() 获得标签的大致高度,但我不知道如何使用标签的高度来设置标签的位置。

【问题讨论】:

    标签: libgdx scene2d


    【解决方案1】:

    您不能直接定位标签,您必须添加到使用 WidgetGroup 的类中,例如 Table。或者您可以使用 Container [应该比 Table 更轻量级] 并为其添加标签:

    Label testLabel = new Label("testme",super.getSkin(),"gameName");
    Container labelContainer = new Container(testLabel);
    labelContainer.bottom();
    

    那么标签应该显示在底部

    【讨论】:

      【解决方案2】:

      您应该先准备好标签,然后再放置:

      skorTextLabel = new Label("Score " + level_skoru, skorTextStyle);
      skorTextLabel.setPosition(
                  ekran_genisligi * 0.5f - skorTextLabel.getWidth() * 0.5f,
                  skorTextLabel.getHeight() * 0.3f);
      

      "skorTextLabel.getHeight() * 0.3f" 距底部的距离。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-21
        • 2013-04-29
        • 1970-01-01
        • 2013-09-02
        • 1970-01-01
        • 1970-01-01
        • 2019-05-26
        相关资源
        最近更新 更多