How to change the position of a TextNode?

I’m building a small debugging window, but I can’t figure out how the heck to move a textnode from it’s starting position.

This is what I’ve got outputting right now (ignore the terrain background):

This is the code I’m using:

        textDebug = TextNode('DebugConsole')
        textDebug.setText("Initializing debug console...")
        textNodePath = aspect2d.attachNewNode(textDebug)

        def updateDebugConsole(task):
            fpsecond = (round(globalClock.getAverageFrameRate(), 0))
            currPos = camera.getPos( )
            fpstext = "Frames Per Second (FPS):     " + str(fpsecond) + "\nCamera Position (XYZ):           " + str(currPos)
            task.delayTime = 1
            return task.again

        taskMgr.doMethodLater(1, updateDebugConsole, "updateDebugConsole")

setPos doesn’t work on this, so can somebody tell me how to change the position of the node?

Thanks :slight_smile:

setPos does indeed work, but the entire screen is only in the range -1 … 1, so setting it to (-5, -5) will move it completely offscreen. Also, it has to be a 3-d coordinate, even though the Y component is not used. Try something more like (-0.5, 0, -0.5).


Ahh that explains it.

Now is there a way to have it redraw it if you change the size of the screen? If I drag the window size when it’s running it seems to slide towards the center of the screen.

I tried adding setPos to the task that runs every second, but that didn’t seem to do it.

You can listen for the event named “window-event”, which is thrown any time the window changes size (or other properties).

Or, you can simply parent your text to base.a2dTopLeft or any of the other corners or edge names as described in the manual, and it will automatically follow the corner or edge.


Do you happen to know the command to reparent a textnode? I’ve tried reparent, reparentTo, and reparent_to with no luck.


Ahh, I was trying to do it on the textNode itself, not the textnodepath.

I used your code and it works perfectly, but the text is appearing just outside the frame (you can just see the bottom edge of it in the top-left corner in the pic above).

What do I need to add so it’s down like 10 units in both the X and Y axis from it’s position?

Thanks for much for the help :slight_smile:

textNodePath.setPos(-0.1, 0, -0.1)

Experiment with the values to get the results you like. You can also use to place it interactively.


Dude you are awesome! Thanks so much!

Here’s the code if anybody wants it:

    def debugConsole(self):
        self.textDebug = TextNode('DebugConsole')
        self.textDebug.setFrameColor(0, 0, 0, 1)     
        self.textDebug.setCardColor(0, 0, 0, 1)
        self.textDebug.setCardAsMargin(0.4, 0.4, 0.4, 0.4)
        self.textNodePath = aspect2d.attachNewNode(self.textDebug)
        self.textNodePath.setPos(0.02, 0, -0.04)
        self.textDebug.setText("Initializing debug console...")
        taskMgr.doMethodLater(1, self.updateDebugConsoleTask, 'RegenConsole')
    def updateDebugConsoleTask(self, task):
        fps = "FPS: " + str(round(globalClock.getAverageFrameRate(), 0)) + "\nXYZ: " + str(camera.getPos( ))
        task.delayTime = 1
        return task.again

When the textnode position’s aspect2d y coordinate is set to 1 or the textnode is parented to a2dTopLeft, part of the text is occluded by the top window border.

I wonder if the textnode placement mechanism on the aspect2d considers the window decorations as part of the frame? Or is it an OS level issue?


1 is the top of the screen. When you set the position to 1, you are setting the baseline of the text (the imaginary line on which the text rests) to the top of the screen, so most of the text is off the screen, except for the bottom parts of lowercase letters and punctuation marks that are visible below the baseline.

So you should set text position to less than 1.0 if you wish it to be visible.

The same is true for a2dTopLeft; in this case the 0.0 value is the top of the screen. If you use a2dTopLeft you have to set the text to a negative y position in order for it to be visible.

The placement of the title bars has nothing to do with it.