0
我一直在努力獲得字體的類型與libgdx工作,我終於做到了。嘗試從字段'GlyphRun.color'讀取空對象引用
但現在它拋出一個異常,我無法弄清楚。
java.lang.NullPointerException: Attempt to read from field 'com.badlogic.gdx.graphics.Color com.badlogic.gdx.graphics.g2d.GlyphLayout$GlyphRun.color' on a null object reference
at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText(GlyphLayout.java:141)
at com.badlogic.gdx.graphics.g2d.BitmapFontCache.addText(BitmapFontCache.java:505)
at com.badlogic.gdx.graphics.g2d.BitmapFontCache.addText(BitmapFontCache.java:487)
at com.badlogic.gdx.graphics.g2d.BitmapFontCache.setText(BitmapFontCache.java:438)
at yt.agar.game.Screens.GameScreen.render(GameScreen.java:213)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
GlyphLayout.java:141: https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/GlyphLayout.java#L141
我畫的字體是這樣的:
BitmapFont font = assetManager.get('arial-96.otf');
font.draw(spriteBatch, "sample text", 10, 10);
我產生bitmapfont這種方式,使用AssetManager
。我嘗試了很多不同的字體,包括truetype字體。
FreetypeFontLoader.FreeTypeFontLoaderParameter font = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
font.fontFileName = "fonts/arial.otf";
font.fontParameters.color = Color.WHITE;
font.fontParameters.borderColor = Color.BLACK;
font.fontParameters.borderWidth = 3;
font.fontParameters.flip = true;
font.fontParameters.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
font.fontParameters.size = 96;
manager.load("arial-96.otf", BitmapFont.class, font);
我看不出我做錯了什麼。