LibGDX FreeTypeFontGenerator NoSuchField exception

↘锁芯ラ 提交于 2019-12-06 05:49:17

Faced similar problem today - you are using new version of freetype extension without updating the libgdx!

The commit to libgdx with name "Adding multi-page fonts to BitmapFont; updating FreeTypeFontGenerator..." added usage of Glyph.id field in FreeTypeFontGenerator.

Glyph class is inside BitmapFont of libgdx. So without updating libgdx - it produces this exception.

You should update libgdx also - this will solve this issue. Or use older version of freetype extension!

use this, worked for me

FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("data/Prosto.tff"));
       font=gen.generateFont(12);
       font.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);

here is a really good tutorial on fonts for LIBGDX. i followed it myself and got no errors

https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDcQtwIwAA&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3JgjFZFQu74&ei=E-R_UrrKGcmrhQf1l4GYBQ&usg=AFQjCNFDDpCbZRhftx7aXKmdcturr9qpDw&sig2=bY_ZJZw-DIgdNObDaXg3EA&bvm=bv.56146854,d.ZG4

it covers how to add the jars and everything

The problem is caused by your not using an instance of FreeTypeFontParameter. So when it goes to generate the font, it doesn't have a set of attributes to assign to it. AFAIK, this is following the principles of the Lazy Initialization:

http://en.wikipedia.org/wiki/Lazy_initialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!