我一直在LibGDX上为Android开发游戏,但我刚刚发现了一个似乎以前没有的问题。我搜索了有关如何使文本平滑的答案,他们说了两件事:


使用FreeType字体。
使用MipMap纹理过滤器。


因此,我使用了FreeType字体,并应用了mipmap,我非常确定过滤器会将字体缩小(因此,使用mipmap),因为字体的大小为200,实际屏幕绝对不是那么大。

我不知道自己是否犯了某种愚蠢的错误或其他错误,但我不知道为什么会发生这种情况,因为我所做的事情似乎可以解决其他人的问题。

所以,这就是我所做的:

我有一个资产类,其中包含我要加载的内容(忘记了精灵),如下所示:

public static BitmapFont font;

public static void load(){
    FreeTypeFontGenerator fontGen = new FreeTypeFontGenerator(Gdx.files.internal("vaques/OpenSans-Bold.ttf")); //free font from fontsquirrel.com
    FreeTypeFontParameter fontPar = new FreeTypeFontParameter();

    fontPar.size = 200;
    fontPar.color = Color.valueOf("ffffff");
    fontPar.genMipMaps = true;

    font = fontGen.generateFont(fontPar);
    font.getRegion().getTexture().setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    fontGen.dispose();

}


然后,将字体加载到主类的create()方法上,并在Screen.java文件上绘制它们。只是获取文本内容,如下所示:

//Outside the constructor (variable declaration part):
OrthographicCamera textCam;
ViewPort textPort;
SpriteBatch textBatch;

//...

//Inside the constructor:
textBatch = new SpriteBatch();
textCam = new OrthographicCamera();
textPort = new ExtendViewport(1600,0,textCam);
textPort.apply(false);

//...

//On the Render() method:
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

textCam.update();
textBatch.setProjectionMatrix(textCam.combined);

textBatch.begin();
    Assets.font.setColor(Color.valueOf("821201")); //whatever the color
    Assets.font.draw(textBatch,Integer.toString((int) (1/delta)), 80, 2400-40);
textBatch.end();

//I draw more text, but it looks the same as this one, just in other colors.


这是该文本的屏幕截图:
It seems I can't post images directly, so here's the link

该图像显示了通过mipmapping缩小后的1024x1024 png圆圈的一部分。当我通过ShapeRenderer绘制它们时,它们看起来完全像文本,但是现在看起来不错。

知道为什么会这样吗?

最佳答案

您的MAC是否支持带有MipMap纹理过滤器的FreeType字体。我对此一点怀疑。确认。

09-30 23:10
查看更多