Libgdx无法从jar文件加载字体

时间:2014-10-20 09:00:43

标签: java fonts libgdx

我正在尝试启动一个BitmapFont,当我运行我的项目时它可以工作但是当我jarsplice项目然后运行它我得到它。

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeExcepti
on: Error reading file: assets\texture\font.fnt (Absolute)
        at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:144)
        at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(Bitmap
Font.java:835)
        at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:106)
        at catt.main.Game.create(Game.java:105)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplic
ation.java:136)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplicati
on.java:114)
Caused by: java.io.FileNotFoundException: assets\texture\font.fnt (The system ca
nnot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:140)
        ... 5 more

这是我加载字体的方式。

fontTexture = new Texture("assets/texture/font.tga");
buttonFont = new BitmapFont(new FileHandle("assets/texture/font.fnt"), new TextureRegion(fontTexture), true);
titleFont = new BitmapFont(new FileHandle("assets/texture/font.fnt"), new TextureRegion(fontTexture), true);

他们所有的领域都是公共静态的。

1 个答案:

答案 0 :(得分:1)

LibGDX has already a function to get Filehandle directly from JAR。我加载这样的字体:

BitmapFont font = new BitmapFont(Gdx.files.internal("texture/font.fnt"));

您还应确保已正确链接资源文件夹。