Im trying to add a Slider into my settings menu and it´s not working at all.
Im initializing my Slider like this, in my Game class:
public Skin sliderSkin;
public void create() {
sliderSkin = new Skin(Gdx.files.internal("assets/skins/slider-skin.json"));
The json looks like this (I have validated it)
{
"com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle": {
"default-horizontal": {
"background": "sliderBackground"
}
}
}
The file is located in:
- Project
-- assets
--- skins
---- slider-skin.json
I also have a sliderBackground.png located in the same folder as the json file.
I´m also getting this error:
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: sliderBackground
Then, im getting this error while running the app:
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: assets/skins/slider-skin.json
Ive tried changing the names of the files, the paths, the way Im initializing the Slider, and other things. I just want a slider to show, preferrably with my custom skin.
A
Skinexpects to find the referenced images asTextureRegions in aTextureAtlas, in your case I cannot see how you are loading the sliderBackground.png into anTextureAtlas.You need to either have an atlas file called
slider-skin.atlasin the same folder as yourslider-skin.json(which contains a region called sliderBackground that has the image), or you need to manually load the atlas and pass it as the second argument to theSkinconstructor.The libGDX tool Texture Packer can be used to create the
TextureAtlas, this is probably the most convenient way.Or, if you want to just make it work for this one case you could try the following:
But I would strongly recommend looking into the texture-packer and using that instead.