Question

I want to calculate the size my Font needs, so my text will be displayed fully in one line without clipping.

Example

|-100px---HERE'S MY TEXT---100px-|

I have the DPI and all there stuff. Testing isn't a way, I am using Libgdx and the text ist display with an Button (Scene2D ui).

Was it helpful?

Solution

Call BitmapFont.getBounds(). The TextBounds it returns will tell you what you need. You can try a medium font, the go up or down based on how big or small the bounds are. I use this method to help scale UI sizes from old Droid 1s up to the new HD displays.

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top