【问题标题】:json file in libgdxlibgdx 中的 json 文件
【发布时间】:2013-11-01 07:47:11
【问题描述】:

我尝试在我的 libgdx 项目中添加 json 皮肤文件,但出现错误:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.SerializationException: Error reading file: gfx/uiskin.json
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: gfx/uiskin.json
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: gfx/uiskin.json
Caused by: com.badlogic.gdx.utils.SerializationException: Field not found: font      (com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle)

我的代码:

public void create() {
    Gdx.graphics.setContinuousRendering(false);
    ui = new Stage();
    skin = new Skin(Gdx.files.internal("gfx/uiskin.json"));
    Gdx.input.setInputProcessor(ui);
    label = new Label("fps", skin);
    label.setText("fps:"+Gdx.graphics.getFramesPerSecond());
    window = new Window("alarm", skin);
    window.setPosition(10, 10);
    ui.addActor(window);
}


public void render() {
    Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    ui.draw();
}

json

{
com.badlogic.gdx.graphics.g2d.BitmapFont: {
            medium: { file: abc.fnt }
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: { font: medium }
},
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default: { font: medium }
}
}

我在asset/gfx 文件夹中有:abc.fnt、abc.png、uiskin.json 我不知道我做错了什么?我搜索了一下,但一无所获。感谢您的帮助。

【问题讨论】:

  • 我尝试过使用皮肤 json 功能,但它对我来说太麻烦了。所以我最终以编程方式构建了皮肤,因为它几乎相同,因为您已经在 json 中使用了 java 类和方法名称。

标签: json parsing libgdx


【解决方案1】:

Window$WindowStyle (WindowStyle Javadoc) 没有 font 字段

可用的字段是:

  • 背景
  • titleFont
  • titleFontColor
  • 舞台背景

你应该做类似的事情。

com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default: { titleFont: default-font, background: default-window, titleFontColor: white },
    dialog: { titleFont: default-font, background: default-window, titleFontColor: white, stageBackground: dialogDim }
}

【讨论】:

  • 不客气。一旦你习惯了一切工作的方式,LibGDX 就很棒!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-13
  • 2015-01-20
  • 2019-10-12
  • 2016-05-23
  • 1970-01-01
  • 2018-07-03
相关资源
最近更新 更多