I want to change a text dynamically using the game engine, that is, the bge module. I want to do it through a text box and I found a question about it. The problem is that in a part of it says to add a text object. I do not know how to do it, because I can not find the option "text object" in the "add" button of the "Logic Editor" bar. The code I´m using is this:
# import game engine modules from bge import render, logic # import stand alone modules import bgl, blf # create a new font object, use external ttf file font_path = logic.expandPath('C://Documents and Settings//Guillermo//Mis documentos//Google Drive//Gproyectos//Proyectos con Blender//Zeyada.ttf') # store the font indice - to use later font_id = blf.load(font_path) chain = 'this is the message' def write(): """write on screen""" width = render.getWindowWidth() height = render.getWindowHeight() # OpenGL setup bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, width, 0, height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() # BLF drawing routine blf.position(font_id, (width * 0.2), (height * 0.3), 0) blf.size(font_id, 50, 72) bgl.glColor4f(1.0, 0.0, 0.0, 1.0) blf.draw(font_id,chain) def update(cont): own = cont.owner chain = own['msg'] # set the font drawing routine to run every frame scene = logic.getCurrentScene() scene.post_draw = [write]
I call to this piece of code, drawtext.py. In the scripting window this is the code I have written:
import drawtext drawtext.chain = 'Hello Mind Maps!'
But I suspect that
drawtext.chain must be linked to a text box from which you can enter text in real time.