我目前正在尝试为我的游戏构建一个简单的加载屏幕,并尝试获取字体的皮肤。
当我尝试使用 skin = game.manager.get("bin/ui/loading.json", Skin.class);
获取皮肤时,会发生此错误:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:540)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:356)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:377)
at com.Sidescroll.game.LoadingScreen.show(LoadingScreen.java:32)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.Sidescroll.game.Sidescroll.create(Sidescroll.java:20)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:58)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:98)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:87)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:477)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:354)
... 6 more
在我当前的 asset/ui 文件夹中有 5 个文件:
loading_0.png - 位图字体图像
loading.fnt - 字体文件
loading.pack - 使用TexturePacker打包单个图像
loading.png -TexturePacker 图像
loadingSkin.json - Skin.json,其中描述了 BitmapFont 和 LabelStyle
我尝试使用 assetmanager 的部分:
//this is the beginning of the show method of my loadingScreen, nothing
//happened before
game.manager.load("bin/ui/loading.pack", TextureAtlas.class);
game.manager.finishLoading();
atlas = game.manager.get("bin/ui/loading.pack");
// do i need an atlas here ?
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
game.manager.finishLoading();
skin = game.manager.get("bin/ui/loading.json", Skin.class);
问题是,我总是需要 map 集吗?如果是,如何创建一个,如果不是,为什么会出现错误?
编辑:我正在使用 libgdx 1.5.4 版本,并且我的项目中没有 android
最佳答案
Skin有许多不同的构造函数,例如:
Skin()
Skin(FileHandle skinFile)
Skin(FileHandle skinFile, TextureAtlas atlas)
Skin(TextureAtlas atlas)
如果您使用 JSON 版本的构造函数,您只需将 json 配置文件传递给它即可。皮肤需要有一些纹理图集,因此默认情况下使用此选项它会查找名为 exatcly 的 .atlas 文件,例如 json 文件。这意味着当您使用文件名loadingSkin.json时:
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
它将查找loadingSkin.atlas文件,因为没有类似的文件,所以会导致错误。
现在你有两个选择:
创建名称与您的 json 类似但具有 atlas 扩展名的文件(.atlas 与 .pack 完全相同 - 您可以更改扩展名或在 TexturePacker 中使用 .atlas 而不是 .pack 创建文件 )
loading.pack -> loading.atlas
更改名称时请注意纹理 .png 文件! (.pack/.atlas 文件内有其名称 - 请与编辑器核对)
使用另一个皮肤构造函数,例如:
Skin(FileHandle skinFile, TextureAtlas atlas)
您正在将文件句柄传递给 .json 和皮肤纹理的 TextureAtlas 实例
TextureAtlas atlas = game.manager.get("bin/ui/loading.pack", TextureAtlas.class); Skin skin = new Skin( Gdx.files.internal("bin/ui/loadingSkin.json"), atlas);
关于libgdx - 制作皮肤时是否必须始终拥有 .atlas 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32978596/