edderkop
(edderkop)
January 8, 2017, 6:49am
1
the trick is to use a mono space font and have a fixed length text object and use python function format() to center the text
example:
text = "{:^32s}".format("TEST")
print(text)
outputs:
" TEST "
here is how it is used in the test blend below
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
own["Text"] = "{:^32s}".format(own["nametag"])
own.resolution = 3
http://15b.dk/blendfiles/centered-text.blend
You can do that too for non-monospaced fonts using blf
edderkop
(edderkop)
January 8, 2017, 7:01am
3
i tried that first ,did not get a good result.
plus this tut is aimed at beginners.
This is good, I use this for formatting. You can also left or right align text, or have a split with a left aligned part and a right aligned part to get a result like this:
Skill: 120
Speed: 15
Wisdom: 2
Age: 10000000
table = [["Skill", 120],["speed", 15],["Wisdom", 2],["Age", 10000000]]
for group in table:
label, value = group
text = '{:<6}{:>6}'.format(label,value)
print(text)
edderkop
(edderkop)
January 9, 2017, 7:22am
6
Smoking_mirror:
This is good, I use this for formatting. You can also left or right align text, or have a split with a left aligned part and a right aligned part to get a result like this:
Skill: 120
Speed: 15
Wisdom: 2
Age: 10000000
table = [["Skill", 120],["speed", 15],["Wisdom", 2],["Age", 10000000]]
for group in table:
label, value = group
text = '{:<6}{:>6}'.format(label,value)
print(text)
i know :yes:
i use something similar her
http://15b.dk/blendfiles/spawner-test.blend