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

房东的猫 提交于 2020-01-05 04:10:17

问题


I have some 3-4 years old game project in libGDX. Now I decided to update it and to move from Eclipse to Android studio. So, I installed A.S. downloaded and installed fresh libGDX project. Then added my old source files and assets. All went well, with some minor changes game runs. Except font.setColor is not working any more - text on screen is black. Transparency is not working neither. That worked well before.

So, my font is generated with Hiero, and it's white (I saw that in some other questions here that it must be white).

font = new BitmapFont(Gdx.files.internal("fonts/bundy.fnt"),
                Gdx.files.internal("fonts/bundy_0.png"), false);
...

font.setColor(0.2f, 0.5f, 0.2f, 1.0f);
font.draw(game.batch, "MAP" , 835,580);

To mention that I used

import com.badlogic.gdx.graphics.GL10;

but now I moved to

import com.badlogic.gdx.graphics.GL20;

since GL10 is not supported any more.

Also, now I'm using GlyphLayout class to get text boundaries. I don't see any other change that could have any influence to font color.

Any idea why setColor is not working? Is there some new step added meanwhile that I have to do?


回答1:


Ok found it!

So, old font image file, that was working well on old libGDX, but won't work in new was in 8 bit png grayscale. Letters were white and background was black.

Now I generated new font with latest Hiero and it was in 8bit png, but in color mode, with white letters and TRANSPARENT background and that works well.

So it was about image format.

P.S. Transparency is still not working...but I can live with that.



来源:https://stackoverflow.com/questions/41487053/font-setcolor-method-not-working-after-libgdx-update-to-latest-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!