简体   繁体   English

Libgdx像素化TextButton

[英]Libgdx pixelated TextButton

I've got a problem in libGDX. 我在libGDX中遇到问题。 I wan't to use a virtual screen size to achive the same looking app on every phone. 我不会使用虚拟屏幕尺寸来实现每部手机上外观相同的应用程序。 I've generated a .fnt file from .ttf with hiero. 我已经使用hiero从.ttf生成了.fnt文件。 Then I've made a TextButton with this .fnt (using a skin). 然后,我使用此.fnt(使用皮肤)制作了一个TextButton。 But the problem is, when I set a virtual screen (480x800) with Viewport, Stage and Table, and I set things like this: 但是问题是,当我使用视口,舞台和表格设置虚拟屏幕(480x800)时,我设置了以下内容:

In the constructor: 在构造函数中:

viewport = new StretchViewport(480, 800);
stage = new Stage(viewport);

In the resize method: 在调整大小方法中:

viewport.update(width,height);

and the text on the TextButton is pixelated. 并且TextButton上的文本被像素化。

带有像素化按钮的屏幕截图

How can I solve the problem, or how should I set the screen to look the same on all devices and get smooth text? 如何解决该问题,或者应该如何设置屏幕在所有设备上看起来都一样并获得平滑的文本?

Thanks! 谢谢!

Use the FreeTypeFontGenerator, it creates a BitmapFont from a .ttf on the fly within your program while it is running so your BitmapFont can be generated at the correct size for the device with no stretching/scaling required. 使用FreeTypeFontGenerator,它会在程序运行时动态地从.ttf中创建一个BitmapFont,这样就可以以正确的设备大小生成BitmapFont,而无需拉伸/缩放。 https://github.com/libgdx/libgdx/wiki/Gdx-freetype https://github.com/libgdx/libgdx/wiki/Gdx-freetype

I would definitely look into the FreeTypeFontGenerator and use a BitmapFont, so you may then use a texture filter which makes a huge difference in quality. 我肯定会研究FreeTypeFontGenerator并使用BitmapFont,因此您可能会使用纹理过滤器,从而在质量上产生巨大差异。 TextureFilter.Linear is what you're looking for. 您正在寻找TextureFilter.Linear。 Not tested, but something along the lines of the following: 未经测试,但遵循以下内容:

    BitmapFont yourBitmapFont = new BitmapFont();
    yourBitmapFont.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);


    Skin tileSkin = new Skin();
    tileSkin.add("white", new Texture("whatever/image/path"));
    tileSkin.add("default", new BitmapFont());

    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = tileSkin.newDrawable("white");
    textButtonStyle.down = tileSkin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.checked = tileSkin.newDrawable("white",
            Color.LIGHT_GRAY);
    textButtonStyle.over = tileSkin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = _yourBitmapFont;     
    tileSkin.add("default", textButtonStyle);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM