【问题标题】:can not prevent libgdx scene2d/ui/ Label from being semi-transparent无法阻止 libgdx scene2d/ui/ Label 半透明
【发布时间】:2017-08-11 17:50:38
【问题描述】:

无论我做什么,标签都是半透明的。 表格内的标签 (labelA,labelB,labelC) 最初是 0% 透明的,但一旦您将其文本设置为 labelA.setText("sometext");,它们就会像他们的兄弟 labelWarning 一样变得半透明。 labelWarning 一直是半透明的。我曾尝试将其单独添加到没有组的阶段(stage.addActor(labelWarning);),将其更改为alabelWarning.getColor().a=1;,但没有区别!期待您的帮助

    Label.LabelStyle ls=new 
    Label.LabelStyle(screenGame.getFont(),Color.BROWN);
    Label labelA=new Label("700 metre",ls);
    Label labelB=new Label("700 metre",ls);
    Label labelC=new Label("1500 metre",ls);

    labelWarning=new Label("sd",ls);
    labelWarning.setWrap(true);
    labelWarning.setPosition(50,30);
    labelWarning.setWidth(500);
    labelWarning.setAlignment(Align.top);

    tableEPS=new Table();
    //tableEPS.debug();

    tableEPS.row();
    tableEPS.add(epgrass).pad(10f);
    tableEPS.add(epdesert).pad(10f);
    tableEPS.add(epsnow).pad(10f);
    tableEPS.row();
    tableEPS.add(labelA);
    tableEPS.add(labelB);
    tableEPS.add(labelC);
    tableEPS.row();


    tableEPS.setFillParent(true);
    tableEPS.pack();

    episodesGroup=new Group();
    episodesGroup.setSize(worldwidth,worldheight);
    episodesGroup.addActor(imagebgclouds);
    episodesGroup.addActor(backbutton);
    episodesGroup.addActor(tableEPS);
    episodesGroup.addActor(labelWarning);

    stage=new Stage(screenGame.getViewport());

    stage.addActor(episodesGroup);

【问题讨论】:

    标签: java android libgdx label scene2d


    【解决方案1】:

    如果您通过 LabelStyle 而不是 Label 本身更改颜色,则会发生这种情况。由于它们都共享相同的 LabelStyle 实例,因此更改样式将影响所有这些实例。确保您通过调用label.setColor() 更改颜色或alpha。

    Label 的颜色乘以 LabelStyle 的颜色,所以如果你不想从样式中弄乱色调,请使用label.setColor(1,1,1, alpha)

    【讨论】:

    • 没用,我什至在labelWarning.setText("sometext"); 之前和之后添加了labelWarning.setColor(16, 14, 119, 1),为labelWarning 创建了不同的LabelStyle,仍然相同,半透明:(
    • 颜色的比例是 0-1,而不是 0-255。
    • 我照你说的做了,但又没有帮助。但是我碰巧发现我用 spriteBatch 绘制的字体也是半透明的。但是按照你所说的设置颜色会使它们不透明,我必须在设置正常颜色后设置 rgba 颜色才能发生这种情况。 batch.begin(); font.setColor(Color.WHITE); font.setColor(1,1,1,1.0f); font.draw(batch,"fps:"+(int)(1f/delta),0,50); batch.end(); 我添加了 font.setColor(1,1,1,1.0f); 行,没有这行,这个 fps 文本也是半透明的,labelWarning 仍然是半透明的
    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多