0

I'm trying to initize a TextButton by giving it a JSON file which contains the style of the button, however I keep getting the following error:

Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Missing LabelStyle font.

After researching what the error was about, it seems that this message shows up when you forget to include a font as part of the TextButtonStyle, however i do include that in my JSON file, so i don't know why it keeps showing.

Here's my json file

{

    "com.badlogic.gdx.graphics.Color":{
    "golden":{"r":255,"g":215,"b":0,"a":1}

    },
    "com.badlogic.gdx.graphics.g2d.BitmapFont": {
      "arcade": {"file": "arcade.fnt"}

    },

    "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
            "default": {
                    "font": arcade,
                    "fontColor": golden
            }
    },

    "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
            "buttonstyle1": {

                    "up": "unpressedtextbutton",
                    "down": "pressedtextbutton",
                    "font": arcade
    }
    }
}

and in the code I initialize the button like this:

Skin skin = new Skin(Gdx.files.internal("buttonstyles.json"),new TextureAtlas(Gdx.files.internal("uistuff.atlas")));
myTextButton = new TextButton("text of the button",skin,"buttonstyle1")

My theory is that somehow it is not reading the font file "arcade.fnt", i'm assuming that the directory it reads the files from is the assets folder, and that's where my "arcade.fnt" file is located.

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
Walu
  • 1

2 Answers2

0

i'm sorry it seems like i made a stupid mistake. Since i declared the font in the JSON file, i erased the font i was previously using in the code to define the button styles, and there was a usage of that font later for a label style, so, it was found to be null and it gave the error.

Walu
  • 1
0

Is it working like this? The official uiskin.json does it like this:

com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
  default: { font: default-font, fontColor: white }
}

No quotes are needed at all not even for the font.

com.badlogic.gdx.graphics.g2d.BitmapFont: { 
  default-font: { file: default.fnt } 
},

Might not be proper JSON but libgdx has it's own lightweight JSON style.

Madmenyo
  • 8,389
  • 7
  • 52
  • 99