gpt4 book ai didi

java - Libgdx 无法从 jar 文件加载字体

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:27 26 4
gpt4 key购买 nike

我正在尝试启动 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);

所有字段都是公共(public)静态的。

最佳答案

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

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

您还应该确保您已正确链接 Assets 文件夹。

关于java - Libgdx 无法从 jar 文件加载字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26461889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com