【问题标题】:animate label text color from transparent to black in libgdx在libgdx中将标签文本颜色从透明变为黑色
【发布时间】:2016-01-21 10:12:53
【问题描述】:

我一直在尝试将标签的颜色从透明变为黑色。我几乎没有成功。标签在整个动画过程中保持完全透明。这是我使用的代码。由于其他 Actor 正常工作,舞台已正确设置。

            Label.LabelStyle lsBy = new Label.LabelStyle(byFont, new Color(0,0,0,0));

            Label byLabel = new Label("text to animate",lsBy);
            ColorAction ca= new ColorAction();
            ca.setEndColor(new Color(0,0,0,1));
            ca.setDuration(0.8f);
            label.addAction(ca);

为标签文本颜色设置动画的正确方法是什么?

【问题讨论】:

    标签: libgdx label scene2d


    【解决方案1】:

    有点混乱,但是标签有两种颜色。一种是其 LabelStyle 中字体的颜色。另一种是它自己的颜色,就像所有演员一样。这两种颜色相互乘以进行绘制。 ColorAction 只影响演员的颜色,不影响样式的颜色。

    您需要将标签样式的颜色保留为白色,并将标签角色本身的颜色设置为透明。

            Label.LabelStyle lsBy = new Label.LabelStyle(byFont, Color.WHITE);
    
            Label byLabel = new Label("text to animate",lsBy);
            byLabel.setColor(Color.CLEAR);
            ColorAction ca= new ColorAction();
            ca.setEndColor(new Color(0,0,0,1));
            ca.setDuration(0.8f);
            label.addAction(ca);
    

    【讨论】:

    • 太棒了。谢谢!
    猜你喜欢
    • 2012-04-22
    • 2013-01-13
    • 2021-10-20
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 2015-10-23
    相关资源
    最近更新 更多