problem atteching text to other root than aspect2d/render2d


I created sprite using the code I found here : [url]Node setup for sprites rendering]

Then I want to attach a text to a sprite I have created and I did not succeed. I try using a TextNode. If I attach it to aspect2d or render2d it is ok. But if I attach it to another node I create to manage my sprites I did not see anything.

Here is my code

from panda3d.core import *


from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
import copy
from direct.gui.DirectGui import *

MARKER_FILE = "data/sprite/marker_red_3.png"

def create_sprites_node_setup(screenWidth, screenHeight, parent = render2d):
   aspect_ratio = parent.getScale()[0]   
   screenOrigin = parent.attachNewNode('screen_origin')
   screenNode = screenOrigin.attachNewNode('screen_node')

   screenOrigin.setPos(-1.0/aspect_ratio, 0.0, 1.0)
   screenOrigin.setScale(2.0, 1.0, -2.0)

   screenNode.setPos(0, 0, 0)
   screenNode.setScale(1.0/(aspect_ratio*screenWidth), 1.0, 1.0/screenHeight)
   screenNode.setTexScale(TextureStage.getDefault(), 1.0, -1.0)
   return screenNode

def create_sprite(filename,x,y):
   texture = loader.loadTexture(filename)

   cm = CardMaker('spritesMaker')
   cm.setFrame(-0.5, 0.5, -0.5, 0.5)
   sprite = cm.generate()   

   node = NodePath(sprite)   

   width = texture.getXSize()
   height = texture.getYSize()

   node.setPos(width/2+x, 0, height/2+y)
   node.setScale(width, 1.0, height)

   return node,texture

class World(DirectObject):
   def __init__(self):
      self.sprites_root = create_sprites_node_setup(,, aspect2d)
      self.marker,self.texture = create_sprite(MARKER_FILE,200,200)
      self.text = TextNode('node name')
      self.textNodePath = aspect2d.attachNewNode(self.text)

      self.text2 = TextNode('node name2')
      self.textNodePath2 = self.marker.attachNewNode(self.text2)

w = World()

Do you have any idea ?
Do I need something else than a TextNode ?
I have to “play” with position and scale on my textnode but nothing change.



Hi, I dunno for sure that this is your whole problem, but…

this line


is probably causing you problems. If I’m correct the sprite code is represented in screen pixels, which means that your text is approx a tenth of a pixel high, soo… Try making it like ten pixels high and see if it works.

(aka np.setScale(10), instead of np.setScale(0.1), this should make it work, or at least it’s a problem I saw)

If you still have problems I’ll try and fix the code, sorry about only giving you one hint :wink:


Yes I tried so change the scale but it does not change anything

Note that your text might also be facing backwards (away from the camera) and therefore invisible. Or there might be other problems.

Try using:


to draw a green wireframe sphere around its bounding volume, to help you find it. If you can’t even see the sphere, try:

print self.textNodePath.getBounds()

to see if you have anything there at all.


@drwr thanks … your idea was good.

with the following is can see the bounding sphere

self.text2 = TextNode('node name2')
self.textNodePath2 = self.marker.attachNewNode(self.text2)

so my problem seems to be my text node is not looking to the camera. so how I can rotate. simply rotate around the good axes ? can I set it to be both sided ? Because I have tried with setR/setH/setP and I did not succeed …



Also try:

self.textNodePath2.setHpr(0, 0, 180)


@drwr thanks again … but none of your solution seems to work. what you have proposed seems logicial but I did not understand what I missed but even if I still be able to see the bounding sphere I cannot see the text it self :frowning:

Well, perhaps there is some other reason you can’t see the text. You’re doing some funny things there with transparency, texture, and alpha scale–what happens if you parent your text node directly to render and avoid all those funny tricks?


I did not think … I will clean my project to make it simple so I can post it here if you have some time to take a look … and try to find a solution before.

thanks again


it seems my problem comes from

screenNode.setTexScale(TextureStage.getDefault(), 1.0, -1.0)

when I create my sprite root.
if I replace it by

screenNode.setTexScale(TextureStage.getDefault(), 1.0, 1.0)

(1.0 instaed of -1.0)

I can see the text but it is up side down.

I will investigate deeper (later).