When you insert a PandaNode into the scene graph, you get back an object of class NodePath. A NodePath is a lot like a pointer to a specific spot in the scene graph — it’s almost exactly the same as a pointer to a PandaNode. Many of the operations that work on PandaNodes are actually methods of class NodePath — including the “setPos” method that you’re looking for.
So the whole thing would look something like this:
You’re trying to place a DirectGui object over an object you have picked out of the 3-d render graph?
Note that the point of the object in 3-d has little to do with the corresponding point under render2d. But you can convert from the 3-d coordinates to the 2-d coordinates.
heres the code of what i used for it to work for me~
"""code used to call textDisplay"""
self.textDisplay("+100",self.pickedObj.getPos(),self.pickedObj)
def textDisplay(self,number,pos, node):
text = TextNode('text')
cmr12 = loader.loadFont('cmr12.egg')
text.setFont(cmr12)
text.setText(number)
text.setTextColor(1,0,0,1)
textNode = render2d.attachNewNode(text)
textNode.setPos(self.map3dToAspect2d(node,pos))
textNode.setScale(0.07)
pass
def map3dToAspect2d(self,node, point):
# Convert the point to the 3-d space of the camera
p3 = base.cam.getRelativePoint(node, point)
# Convert it through the lens to render2d coordinates
p2 = Point2()
if not base.camLens.project(p3, p2):
return None
r2d = Point3(p2[0], 0, p2[1])
# And then convert it to aspect2d coordinates
a2d = aspect2d.getRelativePoint(render2d, r2d)
return a2d
Oh! You can put a textnode and apply it with a billboard effect?
Hmm~ what i really needed was a effect that lets the text appear appear in the game scene. Like picking up objects and a score number like “+10” appears.
You can parent the TextNode into the game scene. For instance, if you want “+10” to appear over your avatar’s head, parent the TextNode to your avatar.