Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upBitmapFont.setFixedWidthGlyphs() does not fix width of first and last characters of text #3239
Comments
|
Please show what is not rendering correctly. |
|
I still see this issue with the latest nightlies. Here's a bare-bones example which illustrates the problem. public class FixedWidthGlyphTest extends ApplicationAdapter {
SpriteBatch batch;
BitmapFont font;
BitmapFontCache fontCache;
float counter;
@Override
public void create () {
batch = new SpriteBatch();
font = new BitmapFont();
font.getData().setScale(2);
font.setFixedWidthGlyphs("0123456789");
fontCache = new BitmapFontCache(font);
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
counter += Gdx.graphics.getDeltaTime() * 10;
String text = String.valueOf((int)counter);
GlyphLayout layout = fontCache.setText(text, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 50, Align.right, false);
Gdx.app.log("FixedWidthGlyphTest", "Layout width of " + text + " is " + layout.width);
batch.begin();
fontCache.draw(batch);
batch.end();
}
}All glyphs used are set to have a fixed width. However, as shown in the log, the width of text with the same number of characters varies. This causes the text to appear to move around. The width, and therefore the position, of the text depends on the width of the last character, which is variable despite the call to setFixedWidthGlyphs(). The width of the first character is also variable so a similar effect would be seen if the text were left-aligned. |
|
Thanks. The problem is in BitmapFont
See the two lines noted. Those lines (before being fixed as above) made the first glyph flush with the left edge and made the last xadvance flush with the right edge. This is nice for variable width fonts because it gives tight fitting bounds for the glyphs. For a fixed width font, it is not so good because you lose the fixed width for the first and last glyph, as you found. I'm not sure what the fix is. BitmapFont Thoughts? |
|
Is it going to be fixed soon? EDIT: I downgraded libgdx to 1.5.6. It works fine. But please repair it :-) |
when using setFixedWidthGlyphs() - see libgdx#3239.
|
Thanks very much for the investigation and explanation, and apologies for the delay in replying. The updated |
|
Closed by #3564. |
When using BitmapFont.setFixedWidthGlyphs() the first and last characters of the text being rendered are not drawn with a fixed width. This appears to have been broken since the changes related to #3074 in libGDX 1.6.0.