Glitching Text Object

Hi there. I’m trying to use a textbox to limit the line length of a text object. In the 3d view it works just fine, but the moment I press P to try it out, it’s as if the textbox doesn’t exist. Also the position and shape of the text are slightly skewed. Does anyone know how to fix these problems?

This is what the text looks like in 3d view.

This is what it looks like in the game.

And Here’s the .blend file.
Text Problem.blend (400.9 KB)

Thanks!
Anodos

i suggest using python, and using the textwrap module
here i use it in a resource: .txt Dialog/quest/book system v2

As @Cotaks said, the textwrap module is the way to go.

There’s an article I’ve written about text formatting in BGE here, you may find it helpful, it explains how to use textwrap and left / center / right formatting. It’s in portuguese, but Google Translation in Chrome showed a good result in english for me.

you could also place “\n” where you want the lines to break. (more work if you have lots of text)

That’s the magic o textwrap: it adds the \n notation automatically, you only have to specify the line width value.

i am fully aware of that ,the drawback is you can’t control where it breaks.

Thanks everybody! I’ll try these solutions and let you know how it goes.

with python that is, it won’t work if you put it into the string Text field property directly.

but a simple


    own = cont.owner   
    own['Text'] = 'line 1\n' + 'line 2\n' + '\nline 4'

or


own['Text'] = 'line 1\nline 2\n\nline 4'

works perfectly fine as well indeed.

you are right, i never noticed this how odd.
properly do to i always go the python route.

i made line break work with string property using this method. (if any needs it)

import bge
cont = bge.logic.getCurrentController()
own = cont.owner 

def stringpropfix(txt=""):
    tmp = txt.split('\\n')
    t = ""
    for line in tmp:
        t += line + "\n"

    return t[:-1]
    
own["Text"] = stringpropfix(own["txt"])

http://15b.dk/blendfiles/linebreaksinproperty.blend

I don’t have a lot of text. Is there any way to simply place a line break in a string?

t= "Line\nLine"

t= """Line
Line"""