Cotaks
(- Click for (UP)Bge resources)
January 24, 2017, 7:18am
1
Hello,
I have looked around and can’t find a solution.
Is there a way to center the text, no matter how long the text will be?
I got a ray shooting in y direction, i want to show/center the text when i hover over an object with a property in it.
i got everything working except the centering of the text, i tried .format() and textWrapper but non of them have the right result. (if i make a text block of 32 characters, and the text is 32 is perfect but when the text changes to lets say 4 characters it is not centered anymore)
edderkop
(edderkop)
January 24, 2017, 9:44am
2
i don’t know if this helps ,i do something similar to what you describe in this test.
http://15b.dk/blendfiles/spawner-test.blend
Cotaks
(- Click for (UP)Bge resources)
January 24, 2017, 10:19am
3
You have the same problem, you notice it less due to i have it at the crosshair.
So how do we get it centered?
edderkop
(edderkop)
January 24, 2017, 10:42am
4
only when the text have a uneven number of characters
edderkop
(edderkop)
January 24, 2017, 11:14am
5
switch rayhit.py with this and you get almost pixel perfect centered text
import bge
cont = bge.logic.getCurrentController()
dict = bge.logic.globalDict
ray = cont.sensors['ray']
if ray.positive:
dict["HUD-Target"].worldPosition.x = 0
words = len(ray.hitObject["objname"])
characterwidth = 0.0924
ofset = (words/2)*characterwidth
dict["HUD-Target"].worldPosition.x -= ofset
dict["HUD-Target"]["Text"] = ray.hitObject["objname"]
else:
dict["HUD-Target"]["Text"] = ""
i have re-uploaded the blend
http://15b.dk/blendfiles/spawner-test.blend
How about to justify text? The option exists in the font tab but does nothing in-game.
edderkop
(edderkop)
January 24, 2017, 12:07pm
7
it would surely be easier if those buttons did something.
Cotaks
(- Click for (UP)Bge resources)
January 24, 2017, 12:16pm
8
switch rayhit.py with this and you get almost pixel perfect centered text
this works for me, thanks for the solution!
edderkop
(edderkop)
January 24, 2017, 12:18pm
9
no problem
remember it only works on mono space fonts
Cotaks
(- Click for (UP)Bge resources)
January 24, 2017, 12:23pm
10
that’s not a problem, i’m using in game text object/font, as long as that works i’m happy