2
votes

When trying to load the default skin from LibGDX's tests

https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests-android/assets/data (uiskin.atlas, uiskin.json, uiskin.png and default.fnt)

I get the following error.

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: No com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle registered with name: default
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:149)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:134)
    at com.badlogic.gdx.scenes.scene2d.ui.TextField.<init>(TextField.java:116)
    at com.badlogic.gdx.scenes.scene2d.ui.TextArea.<init>(TextArea.java:57)
    at me.winter.socialplatformer.menu.ConnectScreen.show(ConnectScreen.java:30)
    at com.badlogic.gdx.Game.setScreen(Game.java:61)
    at me.winter.socialplatformer.Platformer.create(Platformer.java:39)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)

Here's how I'm loading and using the skin:

assetManager = new AssetManager();
assetManager.load("gfx/uiskin.atlas", TextureAtlas.class);

//...

assetManager.finishLoading();

//...

TextArea textArea = new TextArea("test", new Skin(getAssets().get("gfx/uiskin.atlas", TextureAtlas.class)));
textArea.setBounds(100f, 100f, 500f, 500f);

It looks like it can't find this:

com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
    default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor }
},

However, this line is present in file uiskin.json downloaded from the repo. All files are up to date. Additionnally, the error might be linked to the bad json syntax warnings IntelliJ is giving me.

Invalid syntax

1

1 Answers

1
votes

I believe the problem is with how you're trying to load the skin. A few things:

First, I'm not aware of an AssetSupplier class in libGDX. I'm going to assume you meant to put in AssetManager.

Second, in your code you are loading the texture atlas (the file which tells libGDX to to slice and dice the UI image), not the actual Skin file which tells Scene2D how to map the skin to the UI elements.

The cool thing is AssetManager is smart enough to see that uiskin.json is dependent on uiskin.atlas, and will load the atlas file for you if needed. The atlas file, however, knows nothing of the Skin so the reverse does not work.

Try loading the Skin like this instead:

assetManager = new AssetManager();
assetManager.load("gfx/uiskin.json", Skin.class);
assetManager.finishLoading();

ui = new Stage();
textArea = new TextArea("test", assetManager.get("gfx/uiskin.json", Skin.class));
ui.addActor(textArea);

As to the JSON structure, libGDX's example code is using a 'minimal' format that isn't quite proper JSON. The JSON parser that libGDX comes with can read it easily enough, but it would be a good idea to convert it to the 'proper' format for your game. We probably should go ahead and fix it anyways, because this seems to be a recurring question.