1

Programming in Java with LibGDX. I am creating a BitmapFont from the FreeType library.

I want to reference the generated font "public static BitmapFont fooFont" in a .json file:

{
    "com.baglogic.gdx.graphics.g2d.BitmapFont": {
        "font": {???},
    },
    "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
        "default": {"up": "buttonUp", "down": "buttonDown", "font": font},
    },
    "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
        "default": {"font": font}
    }
}

How would I reference fooFont from my class Assets at the ??? variable?

Edit:

After reading over some other posts

Here is some more of my code, along with changes---

from Assets.java:

public static void createSkins() {
        if(menuSkin == null) {
            FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/fooFont.TTF"));
            FreeTypeFontParameter parameter = new FreeTypeFontParameter();
            parameter.color = Color.RED;
            fontOCRA_red = generator.generateFont(parameter);
            generator.dispose();
            menuSkin = new Skin();
            menuSkin.addRegions(menuAtlas);
            menuSkin.add("fooFont", fooFont);
            menuSkin.load(Gdx.files.internal("data/styles.json"));
        }
        if(gameSkin == null) {
            gameSkin = new Skin(Gdx.files.internal("data/styles.json"), gameAtlas);         
        }
    }

from styles.json:

{
    "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
        "default": {
            "up": "buttonBG", "down": "buttonBG_flipped", "checked": "buttonBG", "font": fooFont
        },
    },
    "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
        "default": {
            "font": fooFont
        }
    }
}

The error I am currently getting states:

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: buttonBG

but I am fairly certain that is what was done in the menuSkin.addRegions and add lines from Assets.java, and the textureatlas does show the "buttonBG" item in the correct .pack file. Moving the order around shows that it does not have any of the textureregions or the bitmapfont registered. Is there another reason why it might not register the items?

vimuth
  • 5,064
  • 33
  • 79
  • 116
T H Wright
  • 77
  • 1
  • 9
  • I don't have exact code, but check out the wiki about Skins [link](https://github.com/libgdx/libgdx/wiki/Skin) , note the BitmapFont section on how to declare font in your JSON. Then in code instantiate a Skin object using your json and check out the methods in Skin. ex: skin.getFont("fooFont") – Peter R Jul 24 '15 at 21:05
  • Not quite what I am going for; this blog: http://gigagrand.com/blog/?p=9 shows more of what is needed. Currently attempting to implement it; if I get it working, will post solution. – T H Wright Jul 24 '15 at 21:50
  • I think the answer to this question should give you the answer you're seeking: http://stackoverflow.com/questions/24856201/putting-freetypefont-into-libgdx-skin Apparently you can't load a TTF font through JSON. However, you should still be able to reference the font in the skin JSON as long as you give it the proper name when adding it to the skin programmatically. – Malkierian Jul 30 '15 at 07:41

0 Answers0