How can I change my FreeType Font color? I want to set custom color. I tried do this by using Color color = new Color() but don't work.

And second: can I change my screen coordinates? I use two different cameras. First camera for game and second for text. When I draw text in the (0,0) position, my text is in the center of the screen but I want to have (0,0) in the lower left corner. How do that?


1 Answer 1


When you generate a font you get a BitmapFont object.

You can set it's color like this:

BitmapFont someFont = freeTypeGenerator.getFont(); // or something like that

Also, it's better to change widgets colors, not fonts, for example if you have a Label with the font created above, you can change label's color:


For coordinates read about viewports here: https://github.com/libgdx/libgdx/wiki/Viewports

How to create a color?

Colors in our world contain 4 values - R, G, B and A which means red, green, blue and alpha channel.

RGB are for colors and A is for transparency.

If you want your color to be RED, you set RED to 1, BLUE to 0 and GREEN to 0

If you want your color to be HALF RED and HALF BLUE you set RED to 0.5f, BLUE to 0.5f and GREEN to 0f.

If you look into the LibGDX source, Color constructor takes 4 parameters (R,G,B and A) and these values must be in range 0-1f. It means that if you set your color to new Color(0,0,0,1) - it will be a black color. If you set it to new Color(1,1,1,1) - you'll get a white color. As you can see, maximum value for R, G, B and A is 1. So how to create Colors from RGB values like 77,55,133? You just divide it by 255f and you'll get your R, G and B values.

Correct way:

Color color = new Color(255f/255f, 183f/255f, 77f/255f, 255f/255f);
  • \$\begingroup\$ I tried to use someFont.setColor(Color.RED) and works but only when I use standard colors. When I want to use custom Color my font is still white \$\endgroup\$
    – Land93
    Nov 25, 2016 at 20:27
  • \$\begingroup\$ Then show me how do you create your custom color and how do you set it! :) \$\endgroup\$
    – Jacob
    Nov 25, 2016 at 23:04
  • \$\begingroup\$ First I tried generate BitmapFont with custom color: Color color = new Color(255f, 183f, 77f, 255f); parameter.color = color; font = generator.generateFont(parameter); but it did not work so I tried change BitmapFont color: Color color = new Color(255f, 183f, 77f, 255f); font.setColor = color; and don't work :/ \$\endgroup\$
    – Land93
    Nov 26, 2016 at 15:11
  • 1
    \$\begingroup\$ Try Color color = new Color(255f/255f, 183f/255f, 77f/255f, 255f/255f); and tell me if this works :) Then, I'll explain why it does! :D \$\endgroup\$
    – Jacob
    Nov 26, 2016 at 15:40
  • 1
    \$\begingroup\$ I've edited the answer to explain how to create colors. Question about font sizes deserves another question. We can't provide answers here - in comments ;) If my answer helped you, please mark it as correct and upvote if you wish! :) \$\endgroup\$
    – Jacob
    Nov 26, 2016 at 16:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .