我正在尝试使用TableLayout在LibGDX上创建菜单,但无法读取用于皮肤的json文件。
我使用此代码创建皮肤。
final Skin skin;
FileHandle skinFile = Gdx.files.internal("uiskin.json");
skin = new Skin(skinFile);
Json文件看起来像这样:
{
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: 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.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.SelectBox$SelectBoxStyle: {
default: { listBackground: default-rect, listSelection: default-select-selection, font: default-font, fontColor: white, background: default-select }
},
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.ScrollPane$ScrollPaneStyle: {
default: { vScroll: default-slider, hScrollKnob: default-round-large, background: default-rect, hScroll: default-slider, vScrollKnob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
default: { titleFont: default-font, background: default-window, titleFontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
default: { background: default-slider, knob: default-slider-knob }
},
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: default-rect-pad, fontColorSelected: white, font: default-font }
}
}
我需要一个学校项目,如果你能帮助我,我会很高兴。
这是我得到的错误。
01-22 16:43:18.834: E/AndroidRuntime(25719): FATAL EXCEPTION: GLThread 4254
01-22 16:43:18.834: E/AndroidRuntime(25719): com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:73)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.me.mygdxgame.BlueToothOptionScreen.<init>(BlueToothOptionScreen.java:25)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.me.mygdxgame.Snake.create(Snake.java:17)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:334)
01-22 16:43:18.834: E/AndroidRuntime(25719): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1534)
01-22 16:43:18.834: E/AndroidRuntime(25719): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263)
01-22 16:43:18.834: E/AndroidRuntime(25719): Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.utils.Json.fromJson(Json.java:657)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:94)
01-22 16:43:18.834: E/AndroidRuntime(25719): ... 6 more
01-22 16:43:18.834: E/AndroidRuntime(25719): Caused by: com.badlogic.gdx.utils.SerializationException: Error loading bitmap font: default.fnt
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:464)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:442)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.utils.Json.readValue(Json.java:834)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:410)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.utils.Json.readValue(Json.java:804)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:431)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:420)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:416)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.utils.Json.readValue(Json.java:834)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:410)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.utils.Json.fromJson(Json.java:655)
01-22 16:43:18.834: E/AndroidRuntime(25719): ... 7 more
01-22 16:43:18.834: E/AndroidRuntime(25719): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: default.png
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Texture.load(Texture.java:142)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:108)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:171)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:152)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:120)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:461)
01-22 16:43:18.834: E/AndroidRuntime(25719): ... 17 more
01-22 16:43:18.834: E/AndroidRuntime(25719): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: default.png (Internal)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:74)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:563)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.backends.android.AndroidFileHandle.length(AndroidFileHandle.java:162)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
01-22 16:43:18.834: E/AndroidRuntime(25719): ... 26 more
01-22 16:43:18.834: E/AndroidRuntime(25719): Caused by: java.io.FileNotFoundException: default.png
01-22 16:43:18.834: E/AndroidRuntime(25719): at android.content.res.AssetManager.openAsset(Native Method)
01-22 16:43:18.834: E/AndroidRuntime(25719): at android.content.res.AssetManager.open(AssetManager.java:315)
01-22 16:43:18.834: E/AndroidRuntime(25719): at android.content.res.AssetManager.open(AssetManager.java:289)
01-22 16:43:18.834: E/AndroidRuntime(25719): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:72)
01-22 16:43:18.834: E/AndroidRuntime(25719): ... 30 more
答案 0 :(得分:0)
问题在于:
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } },
它尝试下载BitmapFont。其中包含1个 xxx.fnt 文件和 xxx.png 文件。
您可能正在尝试仅使用.fnt文件。因此这个错误:
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: default.png
使用Hiero生成它们。