[SOLVED] BitmapText.SetTextAlignment() question

Hello there, I continue to be amazed at this game engine and ever thankful for peoples comments on the forums. There is so many dedicated people to this project. Thankyou and Well done on your efforts!



I do have an issue though, ive tried to solve this myself, I would like to do the following for a piece of gui based text



[java]

BitmapFont gFont = assetManager.loadFont(“Interface/Fonts/Console.fnt”);

BitmapText Text = new BitmapText(gFont, false);



Text.setAlignment(BitmapFont.Align.Right);

//Text.setLocalTranslation(0, Text.getLineHeight(), 0);

Text.setText(“Debug_HUD”);

guiNode.attachChild(Text);

[/java]



When i run ths i get a “RuntimeException: Bound is not set”, and we also note that the SetAlignment() is said to be “applicable only when text bound is set”.



I guess my question is how do i set the bounds on text?



I’ve had a look inside the source file for the BitmapText.setAlignment() member and the following throws the exception;



[java]

block.getTextBox() == null

[/java]



It seems that i need to use StringBlock in my project to set the bounds for the text? If this is so then im a bit embaressed to say i cant seem to do it. Because although JME3 seems to use this type, i cant seem to in my project… its as if it doesnt exist… Am i missing a library maybe?



Thankyou for any assistance



Chris

Try this:

[java]BitmapFont gFont = assetManager.loadFont("Interface/Fonts/Console.fnt");

BitmapText Text = new BitmapText(gFont, false);



Text.setBox(new Rectangle(0, 0, 96, 256)); // Set box the text should center in

Text.setAlignment(Align.Center); // Center the text



//Text.setAlignment(BitmapFont.Align.Right);

//Text.setLocalTranslation(0, Text.getLineHeight(), 0);

Text.setText("Debug_HUD");

guiNode.attachChild(Text);[/java]



Ran into the same thing today :wink:

Use crtl+shift+i to fix imports automatically.

1 Like

Just a little hint at java coding standards: You should use lowercase names like mySetting for variables so one can discern classes and variables in the code.

Thanks Baalgarnaal



Just to help others, this is what my final code looked like to get my ‘right justified’ text happening;



[java]

BitmapFont gFont = assetManager.loadFont(“Interface/Fonts/Console.fnt”);

BitmapText Text = new BitmapText(gFont, false);





Text.setText(“Debug_HUD”);

Text.setBox(new Rectangle(0,0, viewPort.getCamera().getWidth(), 80));

Text.setAlignment(BitmapFont.Align.Right);

Text.setLocalTranslation(0, Text.getLineHeight(), 0);



guiNode.attachChild(Text);

[/java]



Hey Norman, i feel honoured you’d reply to my lowly message, and thankyou, yes you are of course correct! My only excuse is that ive only just back to programming last night after not touching on it for many months, and even before that i was on and off all the time. But i will try to follow this rule of thumb.



Kind regards,



Chris