java - libgdx TextButton not working with json -
here menuscreen.java. class screen can set main class , display start menu.
package com.game.screens; import com.badlogic.gdx.game; import com.badlogic.gdx.gdx; import com.badlogic.gdx.screen; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.g2d.bitmapfont; import com.badlogic.gdx.graphics.g2d.textureatlas; import com.badlogic.gdx.scenes.scene2d.stage; import com.badlogic.gdx.scenes.scene2d.ui.skin; import com.badlogic.gdx.scenes.scene2d.ui.table; import com.badlogic.gdx.scenes.scene2d.ui.textbutton; import com.badlogic.gdx.scenes.scene2d.ui.textfield; public class menuscreen implements screen { private stage stage = new stage(); private table table = new table(); private skin skin = new skin(gdx.files.internal("skin.json"), new textureatlas(gdx.files.internal("testingstuff.pack"))); private textbutton buttonplay = new textbutton("play", skin), buttonexit = new textbutton("exit", skin); @override public void show() { table.add(buttonplay).row(); table.add(buttonexit).row(); table.setfillparent(true); stage.addactor(table); gdx.input.setinputprocessor(stage); } @override public void render(float delta) { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); stage.act(); stage.draw(); } @override public void resize(int width, int height) { } @override public void pause() { } @override public void resume() { } @override public void hide() { dispose(); } @override public void dispose() { stage.dispose(); skin.dispose(); } }
i want add simple textbutton application, whenever run this, error involving skin.json file.
exception in thread "lwjgl application" com.badlogic.gdx.utils.serializationexception: error reading file: skin.json @ com.badlogic.gdx.scenes.scene2d.ui.skin.load(skin.java:97) @ com.badlogic.gdx.scenes.scene2d.ui.skin.<init>(skin.java:82) @ com.game.screens.menuscreen.<init>(menuscreen.java:21) @ com.mygdx.game.mygdxgame.create(mygdxgame.java:22) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication.mainloop(lwjglapplication.java:143) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication$1.run(lwjglapplication.java:120) caused by: com.badlogic.gdx.utils.serializationexception: error reading file: skin.json @ com.badlogic.gdx.utils.json.fromjson(json.java:683) @ com.badlogic.gdx.scenes.scene2d.ui.skin.load(skin.java:95) ... 5 more caused by: com.badlogic.gdx.utils.serializationexception: error parsing file: skin.json @ com.badlogic.gdx.utils.jsonreader.parse(jsonreader.java:77) @ com.badlogic.gdx.utils.json.fromjson(json.java:681) ... 6 more caused by: com.badlogic.gdx.utils.serializationexception: error parsing json on line 1 near: : { "white": { "file": "skintest.fnt" } }, "com.badlogic.gdx.scenes.scene2d.ui.textbutton$textbuttonstyle": { "default": { "font": white } } @ com.badlogic.gdx.utils.jsonreader.parse(jsonreader.java:547) @ com.badlogic.gdx.utils.jsonreader.parse(jsonreader.java:55) @ com.badlogic.gdx.utils.jsonreader.parse(jsonreader.java:75) ... 7 more
looking @ sample skin on https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests-android/assets/data/uiskin.json
i noticed there no quotations around style classes, properties , values.
perhaps changing file following work:
{ com.badlogic.gdx.graphics.g2d.bitmapfont: { white: { file: skintest.fnt } }, com.badlogic.gdx.scenes.scene2d.ui.textbutton$textbuttonstyle: { default: { font: white } } }
Comments
Post a Comment