2016-11-23 52 views
0

enter image description hereBitmapFontCache和BitmapFont生成的奇怪行为?

正如你所看到的,数字显示不正确。他们应该看起来像:173和15.4,但他们没有。为什么会发生?我真的不知道。它只发生在较大的字体上,而不是较小的字体。

此外,该错误只出现在分辨率更高的智能手机上。当我将应用程序作为桌面应用程序或分辨率较低(480 x 800)的手机启动时,它不会显示。

我正在用TTF字体随时生成字体。 我的代码:

生成:

public static BitmapFont generateFont(int size, String fontPath) { 
    float scale = 1.0f * Gdx.graphics.getWidth()/Game.WIDTH; 

    if(scale < 1) 
     scale = 1; 

    FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter(); 
    generator = new FreeTypeFontGenerator(Gdx.files.internal(fontPath)); 

    params.size = (int) (size * scale); 

    BitmapFont font = generator.generateFont(params); 
    font.getData().setScale((float) (1.0/scale)); 
    font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); 

    dispose(); 

    return font; 
} 

然后我生成字体:

FONT_115 = FontGenerator.generateFont(115, FONT_TTF_DEFAULT); 

然后我就与这个字体的文本:

layout = new GlyphLayout(font, ""); 
fontCache = new BitmapFontCache(font); 
layout.setText(font, text); 
fontCache.setText(layout, position.x - layout.width/2, position.y); 

所以我的问题: 为什么大字体中的文字显示不正确?

回答

0

下面固定的问题:

FreeTypeFontGenerator.setMaxTextureSize(FreeTypeFontGenerator.NO_MAXIMUM); 

然而,也有一些失败(见图)。

enter image description here