java 无法在 Libgdx 中更改字体颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12762426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:06:52  来源:igfitidea点击:

Can't change font color in Libgdx

javafontslibgdx

提问by ruff1991

I'm trying to change the color of the font I use in my application. But whatever I try the font remains black. I made this font using Hiero font tool.

我正在尝试更改我在应用程序中使用的字体的颜色。但是无论我怎么尝试,字体仍然是黑色的。我使用 Hiero 字体工具制作了这种字体。

My code is something like this:

我的代码是这样的:

SpriteBatch batch = new SpriteBatch();
BitmapFont font = new BtimapFont( Gdx.files.internal(MainAssets.pathToAssets + "font/comic.fnt"), Gdx.files.internal(MainAssets.pathToAssets +  "font/comic.png"), false );

In render where I draw the font:

在我绘制字体的渲染中:

batch.begin();
font.setColor(1, 0, 0, 1);
font.draw(batch, "Hello World!", 0, 0);
batch.end();

I found a similar issue to mine but there was still no solution.

我发现了与我类似的问题,但仍然没有解决方案。

http://code.google.com/p/libgdx/issues/detail?id=370

http://code.google.com/p/libgdx/issues/detail?id=370

采纳答案by nmw

If your font is black then it won't be colour tinted (which is what you're doing when calling setColor). Try generating the font in Hiero again in white.

如果你的字体是黑色的,那么它就不会被着色(这就是你在调用 setColor 时所做的)。尝试在 Hiero 中再次以白色生成字体。

回答by far

You need to set output format with 32-bit depth and white colour with alpha (in case you are using BMFonttool, dont know about the Hiero ).

您需要设置 32 位深度的输出格式和带有 alpha 的白色(如果您使用的是BMFont工具,不知道 Hiero )。

回答by sandeep kundliya

you can use this

你可以用这个

font.setColor(Color.BLUE);

simplest way

最简单的方法

回答by MilanG

Had the same problem with latest libGDX and in my case it was about font image format. For details check this message:

最新的 libGDX 也有同样的问题,就我而言,它与字体图像格式有关。有关详细信息,请查看此消息:

font.setColor method not working after libGDX update to latest version

libGDX 更新到最新版本后 font.setColor 方法不起作用