1
votes

I have a bitmap font built with Hiero, which I'm using in scene2d Labels.

In a single Label instance I need to reduce the font's lineHeight value, but I'd like to leave the other Labels (which are using the same font) intact, so they should keep the default lineHeight of the font.

I've tried to simply adjust the value like this:

label.getStyle().font.getData().setLineHeight(localReducedValue);

However, this has modified all the Labels everywhere -- which, in retrospect, seems logical, since I'm modifying the LabelStyle itself.

Unfortunately something like label.setLineHeight(localReducedValue) doesn't exist, so at this point I see two possible solutions:

  1. Create a copy of the font, set its lineHeight to the value I need, and create a separate LabelStyle with that font; or
  2. Write a custom Label for myself which implements setLineHeight.

The first idea seems wasteful, the second is likely a bit complicated, so I'm hoping there's an easier way of achieving a temporary lineHeight in Labels.

2

2 Answers

3
votes

Nathan Sweet, one of LibGDX's core developers has kindly suggested a solution, which is working perfectly:

Override Label#layout, set line height, call super.layout, set line height back. You need to use layout and not draw because layout computes and caches the glyph positions, draw just draws them.

-1
votes

You can change the LabelStyle of a single Label by doing something like this:

//skin is the skin that you use

Label myLabel = new Label(text, new LabelStyle(skin.get(LabelStyle.class)));

And then you can modify the style without affecting all the labels.