I'm trying to get a bitmap text centered in my game. The text is generated at start, so I wan't to scale & translate it based in its dimensions after the text has been set. This my current code.

text = str(scenesInfo[i][1])
tempBotonText['Text'] = text
textScaleX = 1/len(text)
tempBotonText.localScale[0] *= textScaleX
tempBotonText.localPosition[0] -=len(texto)  * 0.008

But as you can see, the number I am using in the translation is just a guess, and it doesn't work well with any length.

Is there a way I can know the dimensions of the text (it is a bitmap text) after its creation?

  • $\begingroup$ It's hard to figure our what you're doing. What is tempBotonText? $\endgroup$ – dr. Sybren Dec 23 '14 at 22:52
  • 1
    $\begingroup$ I've always worked around this by using monospaced fonts. But you might have some luck with blf.dimensions(fontID, "text here"). It returns a 2-float tuple containing width and height. blender.org/api/blender_python_api_2_72_1/blf.html $\endgroup$ – pqftgs Dec 24 '14 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.