[SOLVED] BitmapText - Center issue

I’m having an issue. I create a bitmapText item and and inside my “Control” item I need to update this field.
This fields is define to be “CENTER”.

Problem is when the text I update is longer then the original it never changes the Box dimensions “WITDH” it starts wrapping all the text beyond the original length.

        	hudText.setBox(new Rectangle(0, 0, hudText.getLineWidth(), hudText.getLineHeight()));
        	hudText.setAlignment(Align.Center);

I’ve also, tried, after setting the new text to get the new HudText Width and redefine the Box the width stays the the as the original. “needRefresh” is set and it goes through this process.
The textbox.width and letters.getTotalWidth() remains unchanged.

    /**
     * @return width of line
     */
    public float getLineWidth() {
        if (needRefresh) {
            assemble();
        }
        Rectangle textBox = block.getTextBox();
        if (textBox != null) {
            return Math.max(letters.getTotalWidth(), textBox.width);
        }
      //  Please note that BitMaptext.getLineWidth() might differ from Font.getLineWidth() -->   scale it with Font.getPreferredSize()/BitMaptext.getSize()
        return letters.getTotalWidth();
    }

Am I doing something wrong?

1 Like

Hi,

That is the expected behavior. If you want it auto-expand then you should not specify a box (set it to null).

To do so, after updating the text you should first set the box to null, then you can use getLineWidth to find the new text width and then redefine the box to the new width.

If you do not want to mess around with BitmapText, you should better use Lemur GUI that takes care of it for you.

1 Like

You can’t do center if you don’t have box set.

Yes, I know about Lemur, but Lemur doesn’t support SpriteSheets (I guess the entire JME doesn’t support sprite sheets). This broke my Gui system, and forced me to handle my own.

    public void setAlignment(BitmapFont.Align align) {
        if (block.getTextBox() == null && align != Align.Left) {
            throw new RuntimeException("Bound is not set");
        }
        block.setAlignment(align);
        letters.invalidate();
        needRefresh = true;
    }
1 Like

I’m not sure what BitmapText has to do with sprite sheets.

Wherever you use BitmapText you can use a Lemur Label.

I was just saying when using images inside Lemur, it doesn’t handle Sprite sheets, each texture needs to be a single image. That breaks my game, I use sprite sheets for icons.

This has nothing to do with Labels inside Lemur.

Yes, because the box will always match the text size in this case so it does not make sense to set alignment.

Yes, but you implied that you cannot use Label instead of BitmapText because of something unrelated. So I was just making sure.

And it wouldn’t take much to fork IconComponent to set the texture coordinates on the quad and support sprite sheets. Probably easier than rolling a whole new GUI.

It wasn’t easier than doing a new Gui. I did a gui years ago. This project is about moving my long term project over from “MY ENGINE” which I did the guis myself. So when converting it, I saw the limitation of Lemur, so I just converted that over also. It didn’t take much to convert it to JME, longest part was separating controls into their own “Control” class to works how JME wants it.

If you want centering, then yes, you need to set alignment or do it yourself.

The solution is

	        	hudText.setBox(null);
	        	hudText.setBox(new Rectangle(0, 0, hudText.getLineWidth(), hudText.getLineHeight()));
	        	hudText.setAlignment(Align.Center);
			setPosition(0, getPosition().y, getPosition().z);

HudText is the bitmapText placed in a node. Doing this works on the changing of the bitmapText letters.

1 Like

I just saw your you Collision Shape Editor on youtube. That looks like a great tool.
I’m assuming that is you…

Do you offer that code to the public???

2 Likes

Thanks

Sorry, it is not ready yet to put on GitHub. I need to clean it up before releasing it along with a bunch of other tools to the public and start maintaining them.

I hope you put it out. I could use such a great tool. Special one that works, so many JME tools on Github don’t work anymore. outdated and not kept up.

1 Like