Reputation: 117
I want to change my font to a specific color using RGB or hex numbers. This is what I have atm.
private BitmapFont font;
This is my initFonts()
method called from create()
in the game
class:
public void initFonts() {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Minecraft.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter();
params.characters ="0123456789";
params.size = 150;
params.color.set(254,208,0,1); //I want to change the color into a custom rgb
font = generator.generateFont(params);
generator.dispose();
}
This makes the font turn completely yellow. 254, 208, 0 is a orangish kind of yellow. What color.set
I think does is convert the values you put in into one of the already available colors to pick from, like Colors.YELLOW
for example. What do I do if I want my specific color?
Upvotes: 1
Views: 878
Reputation: 117
I solved the problem by dividing all the values in params.color.set
with 255f
, meaning it ended up working like this:
params.color.set(254f / 255f, 208f / 255f, 0, 1);
It's because they want it in a value of 0 to 1, not 0 to 255. I hope this helps other people facing this silly problem as well.
Upvotes: 2