LibGDX - 读取文件时出错:uiskin.json

时间:2015-07-22 21:47:15

标签: android json libgdx

我发现了一些关于这个话题的类似问题,但没有人帮助过我。 我从Github下载了“uiskin.xxx”和“default.fnt”文件,用一些测试资产开始游戏,但是uiskin.json文件似乎有问题。 所有文件都在android / assets / Skins文件夹中。

这是加载json文件的代码:

public class Assets {
public static AssetManager manager = new AssetManager();
public static Skin menuSkin;

public static void queueLoading() {

    manager.load("Skins/uiskin.atlas", TextureAtlas.class);
    manager.load("Ressources/DemonHunter.jpg", Texture.class);
    manager.load("Ressources/DemonWarrior.jpg", Texture.class);
    manager.load("Ressources/WingedDemon.jpg", Texture.class);
    manager.load("Ressources/Viking.jpg", Texture.class);

}

public static void setMenuSkin() {

    if (menuSkin == null)
        menuSkin = new Skin(Gdx.files.internal("Skins/uiskin.json"),
                manager.get("Skins/uiskin.atlas", TextureAtlas.class));

}

public static boolean update() {
    return manager.update();
}
}

这是json文件:

{
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: Skins/default.fnt } },
com.badlogic.gdx.graphics.Color: {
    green: { a: 1, b: 0, g: 1, r: 0 },
    white: { a: 1, b: 1, g: 1, r: 1 },
    red: { a: 1, b: 0, g: 0, r: 1 },
    black: { a: 1, b: 0, g: 0, r: 0 },
},
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
    dialogDim: { name: white, color: { r: 0, g: 0, b: 0, a: 0.45 } },
},
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
    default: { down: default-round-down, up: default-round },
    toggle: { down: default-round-down, checked: default-round-down, up: default-round }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
    default: { down: default-round-down, up: default-round, font: default-font, fontColor: white },
    toggle: { down: default-round-down, up: default-round, checked: default-round-down, font: default-font, fontColor: white, downFontColor: red }
},
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
    default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
    default: {
        font: default-font, fontColor: white, background: default-select,
        scrollStyle: default,
        listStyle: { font: default-font, selection: default-select-selection }
    }
},
com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle: {
    default-vertical: { handle: default-splitpane-vertical },
    default-horizontal: { handle: default-splitpane }
},
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 }
},
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
    default-horizontal: { background: default-slider, knob: default-slider-knob },
    default-vertical: { background: default-slider, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
    default-horizontal: { background: default-slider, knob: default-slider-knob },
    default-vertical: { background: default-slider, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: { font: default-font, fontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
    default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor }
},
com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle: {
    default: { checkboxOn: check-on, checkboxOff: check-off, font: default-font, fontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
    default: { fontColorUnselected: white, selection: selection, fontColorSelected: white, font: default-font }
},
com.badlogic.gdx.scenes.scene2d.ui.Touchpad$TouchpadStyle: {
    default: { background: default-pane, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle: {
    default: { minus: tree-minus, plus: tree-plus, selection: default-select-selection }
},
com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
    default: {
        label: { font: default-font, fontColor: white },
        background: default-pane
    }
},
}

我不确定开头的路径是否正确,但我尝试了一些不同的路径以确保这不是错误。

这是错误:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: Skins/uiskin.json
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:82)
    at com.valhallagames.hfp.data.Assets.setMenuSkin(Assets.java:26)
    at com.valhallagames.hfp.screens.Splash.render(Splash.java:34)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: Skins/uiskin.json
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:683)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
    ... 6 more
Caused by: com.badlogic.gdx.utils.SerializationException: 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:416)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:410)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:867)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:404)
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:681)
    ... 7 more
Caused by: com.badlogic.gdx.utils.reflect.ReflectionException: Class not found: com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle
    at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:30)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:414)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:28)
    ... 12 more

谢谢你的每一个答案:)。 干杯,Joshflux

2 个答案:

答案 0 :(得分:1)

正如James Skemp在评论中所建议的那样,在IDE中打开uiskin.json文件并从中删除以下行或类似文件并保存文件:

com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
    default: {
        label: { font: default-font, fontColor: white },
        background: default-pane
    }
}

现在它应该可以正常工作。我不知道它为什么会起作用。

答案 1 :(得分:0)

你有地图集文件吗?如果没有,你应该。它们的用法如下:

    FileHandle fileHandle = Gdx.files.internal("pathToMyJsonFile/fileNameForMyJson.json");
    FileHandle atlasFile = fileHandle.sibling("fileNameForMyJson.atlas");
    if (atlasFile.exists()) {
        Gdx.app.log("MyGame", "atlas file is loaded");
        skin.addRegions(new TextureAtlas(atlasFile));
    } else {
        Gdx.app.log("MyGame", "atlas file is NOT loaded");
    }

Atlas文件在png文件中定义纹理的位置。您可以找到API for TextureAtlas here

在json文件中,有一个对default-pane的引用。那里定义了 NOT 。 Atlas文件是应该定义的地方。

我希望它有所帮助。 =]