Best way to do text in the game engine?

I want to add some dialog to my game, and am wondering what the best way to do text is. I know I can use this method, but I think I saw an easier and much better looking method on here before. If anyone knows of a better way to do text, I would appreciate it, thanks.

Latest blender build has text support, all you need to do is to add a text and go to logic editor and add text propery,>assign text or numbers via python for best result ,or logic brick actuator >assign property.

Oh wow! That’s awesome! Thank you so much, I really need to keep aware of these changes.

You re wellcome!

How would I go about making it multi-lined? Would I have to use a different text object for each line, or is there a way to make a line-break? Thank you for any help.

If you have ever looked into JavaScript, then you may know
, a slightly bizarr looking Command.
You can change the text String via Python and if your Python-coded String includes a
, then there will be a Break at any

An Example which I have made recently for trying it out myself:

from bge import logic as g

Hate is a Force that will 
push off anyone around you, 
as its Fire as cold as Ice will 
spread its Arms from within 
you in an Attempt to perish 
whomever comes close."

(Don’t bother about the Text, I just copied it from my Script)

Thank you C.A.ligari. I was thinking it was the newline character, but I had the dash backwards, and I didn’t even know if I was using it right since I have never used it before.

EDIT: I just tried the newline character, and it doesn’t work. If I get the string “You can jump
off walls” from an object property, it will show up as “You can jump
off walls”, no line break. If I type it directly in the python code like you showed in your example, it shows up as “You can jump ᨅoff walls”, also with no line break. Am I doing something wrong, or does this method just not work?

EDIT2: It turns out that the problem was that I was using 2.61, and newline was added in 2.62. I still have one problem though, the newline only works if the string is directly in the python script. If I use a string property, it just shows "
" instead of a newline.

Hmm. If I open an old project/blend file and try to add a text object there it doesn’t work (text goes all pixeled like before),
but if I add text in new fresh blend it works just fine. Am I missing something here? :slight_smile:

Oh never mind. It seems that text can’t be too small or the camera can’t be zoomed in to too closely / small size in Orthographic mode, that will still make the font pixelised. I thought the text rasterisation would ignore such things since its’ size only matters to the pixels, not the 3d world size?

Also using keyframed animations on Text-objects seems to be very slow for now. I tested a simple 2 keyframes on simple scale and it halted the game too badly to even consider keeping it in.

Another way is to add text via python (blf,bgl)

(taken from reference site)

import bge
import bgl
import blf

logic = bge.logic
render = bge.render

def fontInit():
    font_path = logic.expandPath('//assets/fonts/arial.ttf')
    logic.font_id = blf.load(font_path)
    scene = logic.getCurrentScene()
    scene.post_draw = [write]

def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.gluOrtho2D(0, width, 0, height)

    # BLF drawing routine
    font_id = logic.font_id
    blf.position(font_id, (width * 0.01), (height * 0.01), 0)
    blf.size(font_id, 20, 52)
    blf.draw(font_id, "Hello World")


^is that better than a text object? as in less resource heavy?