读取文件skin.json时出错 libgdx。

3
我正在尝试为我和朋友们正在尝试制作的游戏创建一个主菜单。我们使用Eclipse + LibGdx工作,但我真的不知道该怎么做。我直接使用了代码,但是我无法在任何博客/论坛/教程上找到任何帮助。 (http://www.gamefromscratch.com/post/2015/02/03/LibGDX-Video-Tutorial-Scene2D-UI-Widgets-Layout-and-Skins。)
    package com.mygdx.game;
    import com.badlogic.gdx.ApplicationAdapter;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.GL20;
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.scenes.scene2d.InputEvent;
    import com.badlogic.gdx.scenes.scene2d.Stage;
    import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
    import com.badlogic.gdx.scenes.scene2d.ui.Skin;
    import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
    import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
    import com.badlogic.gdx.utils.Timer; 
    import com.badlogic.gdx.utils.viewport.ScreenViewport;
public class MyGdxGame extends ApplicationAdapter { private Skin skin; private Stage stage;
@Override public void create () {
// 创建皮肤和舞台 skin = new Skin(Gdx.files.internal("uiskin.json")); stage = new Stage(new ScreenViewport());
// 创建按钮并设置大小 final TextButton button = new TextButton("点击我",skin,"default"); button.setWidth(200); button.setHeight(50);
// 创建对话框 final Dialog dialog = new Dialog("点击消息",skin);
// 添加按钮监听器 button.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { dialog.show(stage); // 显示对话框 Timer.schedule(new Timer.Task() { @Override public void run() { dialog.hide(); // 隐藏对话框 } }, 10); } }); stage.addActor(button); // 将按钮添加到舞台
Gdx.input.setInputProcessor(stage); // 设置输入处理器为舞台 }
@Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.act(Gdx.graphics.getDeltaTime()); stage.draw();
}
public static void main(String[] args) {;} }

uiskin.json文件:

    {
     com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: Razer.fnt     } },
      com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
      default: { down: default-round-down, up: default-round, font: default-font     },
      },
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: { default: { titleFont: default-font } } }

desktoplauncher:

    package com.mygdx.game.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.mygdx.game.MyGdxGame;
public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); new LwjglApplication(new MyGdxGame(), config); } }

错误:

在“LWJGL应用程序”线程中发生异常,com.badlogic.gdx.utils.SerializationException:读取文件时出错:uiskin.json
    在com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin中。 (Skin.java:74)
    在com.mygdx.game.MyGdxGame.create(MyGdxGame.java:26)
    在com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)处
    在com.badlogic.gdx.backends.lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:124)
由于com.badlogic.gdx.utils.SerializationException而引起:读取文件时出错:uiskin.json
    在com.badlogic.gdx.utils.Json.fromJson(Json.java:694)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
    ... 4 more
由于com.badlogic.gdx.utils.SerializationException而引起:找不到字体文件:Razer.fnt
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 3.read(Skin.java:452)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 3.read(Skin.java:443)处
    在com.badlogic.gdx.utils.Json.readValue(Json.java:884)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 1.readValue(Skin.java:408)处
    在com.badlogic.gdx.utils.Json.readValue(Json.java:852)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 2.readNamedObjects(Skin.java:429)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 2.read(Skin.java:418)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 2.read(Skin.java:414)处
    在com.badlogic.gdx.utils.Json.readValue(Json.java:884)处
    在com.badlogic.gdx.scenes.scene2d.ui.Skin $ 1.readValue(Skin.java:408)处
    在com.badlogic.gdx.utils.Json.fromJson(Json.java:692)处
    ... 5 more

谢谢。请记住我完全迷失了方向,现在只能寄希望于这里了。 对于我在这篇文章中犯的任何错误,请原谅!

-ed

2个回答

2
那个错误基本上是在说皮肤json有问题。虽然格式看起来挺好的,但我认为堆栈跟踪中可能还有更多信息。请检查一下Razer.fnt的路径。如果这样还不行,请在此处粘贴完整的堆栈跟踪。

0
Font file not found: Razer.fnt

你需要使用Hiero工具来创建字体。将生成的两个文件放在Android项目的Assets文件夹中。如果你没有“Razer字体”,可以在一些字体网站上搜索。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接