Justify text centered

when I click centered in the text alignment panel, it looks good.

when I press P the text moves over to ‘Right’ justification.

how can I fix / work around this?

Notice in this file, the center of the text object is offset from the center of the icon,

it makes this type of text based icon / font menu tricky… too tricky.

rotate menu = [ and ]


RotateMenu.blend (519 KB)

Google for string format justify or alignment. You can use python string’s format function to get left right or center justify.

yes, but this won’t move the center of the object will it?

Ohh that menu looks cool. Where is supossed the text to appear? on the ceneter?

Anyway if I where to code this I would do it very diferently, since I hate SCA. To start with I would use BGECore wich includes text alignation by default. BGECore uses Labels, wich is text rendered with the BLF module, here you have the source code: https://github.com/elmeunick9/BGECore/blob/master/template/data/core/interface/label.py

From the source code the most important lines on this matter are from 245 to 263, as you can see you need to use blf.size() and blf.dimensions() to calculate the new position the text must be rendered to in order to look well aligned. You of course can just do that but you would have much more advantages if you were to use all BGECore (text shadow, text antialiassing, line wrap, blur, leading, etc…)

Wow, now that I got home and looked at your blend, that’s a neat idea.
Did you make the font yourself? There are settings within a font for adding spacing around letters, I recently used “birdfont” to adjust the spacing of some fonts I made using another program.

If you want to control the alignment of your normal text though, here’s what i was talking about:

text = '{0: ^12}'.format("hello") 

This will place “hello” in a block of spaces 12 letters wide, essentially center aligning your text.

You can find more examples here:

There’s some interesting possibilities there, such as tables and other stuff you may find useful for your projects, though it might not help with this specific problem.

For my point of view, text object is one of the worst aspect of the BGE. I’m not a profesionnal so I’m not sure to understand everything but in most of other game engine, they speak about textbox… maybe a new feature in next bge version… Anyway, finding a way (an EASY way) to correctly align dynamic texts would be so usefull…

1 Like

If you use BGECore it’s very easy.

Sorry for the glitches in the video, camstudio had some problems.

very cool that font.