I just recently updated my Libgdx project from 1.4.x to 1.6.1. I use BitmapFontCache for my dialogue in my game, drawing a string character by character using BitmapFontCach
OK, I know where the issue lies, and I'm pretty certain it's a bug in libgdx.
I also have a workaround, although it's a little hacky.
The Problem
When GlyphLayout
wraps a line on a space character, it optimises out the terminating space. So with the space removed, the total number of glyphs in the layout is now less than the number of characters in the string. The more lines that get wrapped on a space character, the bigger the discrepency will be between the two.
The Workaround In order to work out what length to use for rendering the full text therefore, we need to count the number of glyphs in the GlyphLayout instead of the number of characters in the String. Here's some code that does that...
private int calcLength(GlyphLayout glyphLayout) {
int length = 0;
for(GlyphLayout.GlyphRun run : glyphLayout.runs) {
length += run.glyphs.size;
}
return length;
}
The GlyphLayout
to pass in will be the one that was returned by the BitmapFontCache.addText()
method.