Who told you that the text is static ? It’s modifiable if you use mayChange=1.
Take advantage of offscreen DirectEntry and instance it to the avatar’s top, so you would get the blinking cursor too.
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
chatTextParent=aspect2d.attachNewNode('chat text dummy')
self.chatTextDE = DirectEntry( parent=chatTextParent,
text='SMILEY', # the name
initialText='_____________ press Enter to chat _____________',
chatTextParent.setZ(-5) # put it offscreen
# dummy node for the billboard, or else the result would be weird
# if there is translation on the node
chatTextOutputParent=smi.attachNewNode('chat text dummy')
self.chatTextOutput.setZ(smi.getTightBounds()+1) # put it above smiley
# setting '' as text places the cursor on the left side, not center.
# So use space, nobody would notice.
print 'START INPUT'
# keypress input check is performed after DirectEntry command,
# so let a frame pass by before accepting the key
print 'STOP INPUT',c
ynjh_jo, once again you are doing something clever here and I am trying to understand it. The difficulty is understanding the instanceUnderNode function, which is not well described in the docs:
It’s the description of instanceTo that is really bad. It’s the kind of thing that really needs a picture (of the scene graph before and after the opetation) to be comprehensible. The page on instancing in the manual helps though.
If I understand your code, you create a DirectEntry (chatTextDE) in the 2D scene graph, and move it off screen. But then you use instanceUnderNode to create a node, chatTextOutput, which I think has two parents, chatTextOutputParent in the 3D scene and chatTextDE in the 2D scene. It is as if chatTextOutput is a copy (instance) of chatTextDE that moves around in the 3D scene, giving you the behaviour of a DirectEdit without actually placing one into the 3D scene. Do I have the right idea?
Why would you do this? Is it not possible to simply place a DirectEdit in the 3D scene? And is this why you have to press a key to start typing rather than clicking on the text field?
I hacked your code to place the DirectEdit chatTextDE directly into the 3D scene graph instead (I attached it to chatTextOutputParent) and this seemed to confirm my suspicion: typing into the DirectEdit didn’t work. But I’m surprised because I don’t see why this shouldn’t just work.
The returned node of instanceTo is referencing the same actual node. You can’t have individual different states across instances this way.
So, you have to create a dummy parent node above each instance, which is exactly what instanceUnderNode does. The returned node is the dummy parent, so you have a free slot for different states, which propagates to the individual instance.
Yes, you’ve got the idea.
Now you know that DirectGUI objects don’t work outside aspect2d.