Label position discrepancy

Some simple code:

[java]
Vector2f imgLSize = new Vector2f(16f, 16f);
Vector2f labelLSize = new Vector2f(258f, 16f);
// Legend

    Element img1 = new Element(screen, null, new Vector2f(1f, 40f), imgLSize, Vector4f.ZERO, "Interface/GUI/Map/Resource.png");
    Label iL1 = new Label(screen, new Vector2f(19f, 40f), labelLSize, resize, "Interface/GUI/infoBoxGreen.png");
    iL1.setText("Resource Node");
    iL1.setTextVAlign(BitmapFont.VAlign.Top);
    Element img2 = new Element(screen, null, new Vector2f(1f, 56f), imgLSize, Vector4f.ZERO, "Interface/GUI/Map/Lightning.png");
    Label iL2 = new Label(screen, new Vector2f(19f, 56f), labelLSize);
    iL2.setText("Lightning Storm");

[/java]

The visual result.

And some details.
As you can see, both in the code and the result of that code, the text isn’t top-aligned. The green box is a simple frame image with the inside transparent and shows where the actual control is located on the screen. But the text is offset by 9 pixels from the top. I would expect to have the bottom part of the text to be at the same level as the lower part of the box. Not 2 pixels lower. And that is if VAlign wasn’t set. Which it is, at Top as shown on line 8.

The box frame is simply there to demonstrate the discrepancy, it won’t be used in the game, at least not there. That means I could “fix” it by cheating the control higher, probably 6 pixels would center the whole thing. I would much prefer if the text was at its proper place.

There’s also the possibility I’m doing something wrong. But, well… I would be surprised if that was the case. I can’t get them all wrong now I can? :stuck_out_tongue:

@madjack

This is not you. I’m aware of this problem and haven’t figured out hat bone-head maneuver I made to make this happen. Here is what I have figure out so far:

  1. Labels act as if they all have the same UID.
  2. Only the last label added acts as expected.

I’ll try and figure this out today and get the fix in place.

EDIT: Oh… this is not related to what I said, but you’ll find what I said is annoying and accurate =) The alignment issue with BitmapText has to do with a discrepancy in height between the element and the BitmapText. They all appear slightly below the position you set. I’ll see about account for this internal to the element class, though, it may take a day or two so I can test at various text sizes to make sure it actually works as expected.

@t0neg0d said: I'll try and figure this out today and get the fix in place.

Ah, cool. :smiley: No rush. I’ll just leave the code as it is knowing it’s properly placed. Eventually I’ll get a surprise. :wink:

Thanks again.

1 Like