2016-01-12 93 views
-2

我有負載的問題TTF文件,我的代碼:組自定義字體,libgdx崩潰

Label migliaLabel; 
migliaLabel = new Label("label", new Label.LabelStyle(new BitmapFont(Gdx.files.internal("Kalam-Regular.ttf")), Color.MAGENTA)); 

文件卡拉姆 - Regular.ttf是在文件夾資產/卡拉姆,Regular.ttf 但是當我運行遊戲時,android studio會出錯:

FATAL EXCEPTION: GLThread 125 com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: Kalam-Regular.ttf at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:665) at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.(BitmapFont.java:475) at com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:114) at com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:107) at com.surfsurvivor.game.GameClass.show(GameClass.java:181) at com.badlogic.gdx.Game.setScreen(Game.java:61) at com.surfsurvivor.game.SurfClass.create(SurfClass.java:26) at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Invalid padding. at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:488) at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.(BitmapFont.java:475)  at com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:114)  at com.badlogic.gdx.graphics.g2d.BitmapFont.(BitmapFont.java:107)  at com.surfsurvivor.game.GameClass.show(GameClass.java:181)  at com.badlogic.gdx.Game.setScreen(Game.java:61)  at com.surfsurvivor.game.SurfClass.create(SurfClass.java:26)  at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254)  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

我該如何解決它?

回答

0

我解決了使用Hiero,你可以從網站libgdx下載並轉換文件ttf文件.fnt。現在它適用於我。

現在設置字體:

migliaLabel = new Label("label", new Label.LabelStyle(new BitmapFont(Gdx.files.internal("Kalam-Regular.fnt")), Color.MAGENTA));