作者:廖劫讲 | 来源:互联网 | 2023-05-19 00:22
我试图在libgdx中创建一个游戏,我想加载一个ttf
字体并在屏幕上绘制一些文本但它在我的Android设备上不起作用,我明白了Unfortunately, game has stopped
.我使用Android Studio作为IDE.它适用于桌面.
这是我加载字体的方式:
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
我在logcat中收到以下错误:
03-07 20:41:44.902 9759-9779/com.mygdx.game.android E/AndroidRuntime? FATAL EXCEPTION: GLThread 5345
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: font.ttf (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.g2d.freetype.FreeType$Library.newFace(FreeType.java:69)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.(FreeTypeFontGenerator.java:106)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:42)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1513)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
Caused by: java.io.FileNotFoundException: font.ttf
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:315)
at android.content.res.AssetManager.open(AssetManager.java:289)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.g2d.freetype.FreeType$Library.newFace(FreeType.java:69)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.(FreeTypeFontGenerator.java:106)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:42)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1513)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
这是文件的位置:
这是我的build.gradle
档案
1> P.T...:
尝试:
... Gdx.files.internal("font.TTF"));
Android文件系统区分大小写.