In game text help.

Heyas everyone ^^

I have been looking through the TextNode manual and class list and it seems that there isnt a method to set the position.

OnScreenText wont work as the camera is constantly moving.

i need the score to float up above the places where the score increment appears. It fades gradually and then disappears

Anyone have any codes or ideas to share? :smiley:

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:

txtnode = TextNode(yada yada)
txtnp = render2d.attachNewNode(txtnode)
txtnp.setPos(…)

The positioning seems to work now ^^ thanks.

It seems that i have bumped into another problem. I cant see the text that i wish to display!

Heres the code i’ve used:

def textDisplay(self,number,pos):
                text = TextNode('text') 
                text.setText(number)
                text.setTextColor(1,0,0,1)
                textNode = render2d.attachNewNode(text) 
                textNode.setPos(pos)
                textNode.setScale(0.07)
                pass

and i use:

self.textDisplay("+100",self.pickedObj.getPos()) 

to call it.

Try this line:

self.textDisplay("+100",self.pickedObj.getPos(aspect2d))

That way you will get the position relative to aspect2d.

It didnt work! T_T

Do you have any other suggestions to make it appear? ^^

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.

It’s a little more complex than just doing node.getPos(render2d), though. See this thread: https://discourse.panda3d.org/viewtopic.php?t=2022

David

Woohooo! It worked! :smiley:

Thanks for all the help ^^

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

By the way~ is there any panda class that allows the printing of 3d billboard text that can be changed dynamically?

You can certainly change the text on a TextNode dynamically. And you can make it a 3-D billboard. Not quite sure what else you’re asking.

David

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.

David