1

I am creating a Label using a truetype font and the gdx-freetype-platform plugin/library.

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/helveticablackoblique/Helvetica-Black Oblique.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter shadowParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    shadowParameter.size = 100;
    shadowParameter.borderColor = Color.BLACK;
    shadowParameter.borderWidth = 3;
    shadowParameter.shadowColor = Color.GRAY;
    shadowParameter.shadowOffsetX = 3;
    shadowParameter.shadowOffsetY = 3;

    BitmapFont bitmapFontShadow = generator.generateFont(shadowParameter);
    generator.dispose();

    final Label.LabelStyle shadowStyle = new Label.LabelStyle(bitmapFontShadow, Color.WHITE);
    final Label startNewGameLabel = new Label("NEW GAME", shadowStyle);

    startNewGameLabel.debug();
    startNewGameLabel.setPosition((Gdx.graphics.getWidth() / 2) - (startNewGameLabel.getWidth() / 2), (Gdx.graphics.getHeight() / 4 * 3) - (startNewGameLabel.getHeight() / 2));
    stage.addActor(startNewGameLabel);

I've ommitted the other Labels on the screenshot, but they're all created in the same way, though the larger one uses parameter.size = 200

As you can see from the green box created by debug, the width seems to match (it may be slightly off because of the shadow/border but I can handle that) but the height is roughly half of the font. It means when I add a listener to it, the touch doesn't marry up to the actual font on screen.

Any idea what I'm doing wrong?

enter image description here

Jim
  • 995
  • 2
  • 11
  • 28
Russ Wheeler
  • 2,590
  • 5
  • 30
  • 57
  • It may be helpful to look at this [answer](http://stackoverflow.com/a/18557487/2016436). – asherbret Sep 20 '16 at 14:01
  • So what you're saying is I can't just add a label to my stage, it has to be inside a table? And then what? The Label would match the Table cell size, rather than the font size? Surely that's not right? – Russ Wheeler Sep 20 '16 at 23:28
  • According to the [Table Wiki](https://github.com/libgdx/libgdx/wiki/Table): "Tables are intended to be used extensively in scene2d.ui to layout widgets...". Since `Label` is a `Widget` I think that the LibGDX way is indeed to use Labels in the context of Tables, and usually not to add them directly to the Stage. – asherbret Sep 21 '16 at 07:04
  • ok, i'll try sticking it in a table to see what that does. However, I was setting the font size, and I'd rather do that than try and set a table cell size and fit my font to that – Russ Wheeler Sep 22 '16 at 00:26
  • I've realised it was the font file I was using. The ttf file. When viewed through a font viewer software, all the diff sizes overlapped each other. I gave about an hour to trying to edit the file, but didn't know where to start. Thanks for your help though @liga – Russ Wheeler Sep 26 '16 at 15:09

0 Answers0