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
Can't change font color in Libgdx
提问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.
我发现了与我类似的问题,但仍然没有解决方案。
采纳答案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
回答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