But when I try to change this text in a later stage of the game I have to destroy the object first and then make a new one. Is there another way of doing this?
I tried to do
self.infoText.text = 'Updated text'
and
self.infoText.setText = 'Updated text'
But somehow this does not works. The only thing that seems to work is to destroy it first
Read the manual once again.
There is mayChange option, if you set it true, the text would be editable.
And the way to change it are :
self.infoText.setText(‘new text’)
OR
self.infoText[‘text’]=‘new text’
What I try to do is update an image according to the position of the mouse. Somehow I am unable to get the position of the mouse. Below is my code but I can’t even place the mouse position in the textObject.
import direct.directbase.DirectStart
from pandac.PandaModules import TextNode
from pandac.PandaModules import Point2,Point3,Vec3,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.DirectGui import *
from pandac.PandaModules import TransparencyAttrib
import cPickle, sys
from pandac.PandaModules import TextNode
class World(DirectObject):
def __init__(self):
foo=1024 / 600
self.imageObject = OnscreenImage(image = 'textures/background.png', pos = (0, 0, 0), scale=(1024.0/800.0,1,1024.0/600.0), parent=render2d)
self.imageObject.setTransparency(TransparencyAttrib.MAlpha)
self.gameTask = taskMgr.add(self.drawMenu, "drawMenu")
self.menuItems = []
for item in range(3):
self.menuItems.append(
OnscreenImage(image = 'textures/button.png', pos = (-0.5, 0, -0.2+(0.10342*item)),scale=(256.0/800.0,1,64.0/600.0),parent=render2d)
)
self.menuItems[item].setTransparency(TransparencyAttrib.MAlpha)
self.infoText = OnscreenText(text = 'Mohahah', pos = (-0.5, 0.02), scale = 0.07, mayChange=1)
def drawMenu(self, task):
menuRowHeight = 32
mousePosition = self.getMousePosition
self.infoText.setText(str(mousePosition))
def getMousePosition():
p = None
if base.mouseWatcherNode.hasMouse():
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
p = Point3(x,y,0)
return p
w = World()
run()
I want to create my own buttons and not use the directbutton because that is really ugly. Next to that I want it to be dynamic so when I change a tuple or a file the menu changes… Next to that how can I detect a mouse click event?
Doesn’t the taskmanager assumes to keep playing the loop until you tell it to stop? anyway I included
return Task.cont
Documentation is poor about this(Actually it has to much unstructured info)
What I really want to know is
How can I display the coordinates I get from getMousePosition on the screen and how can I listen to the “mouseButtonClicked” event?
I would clearly not say Panda3D documentation is unstructured.
It’s the opposite .
BUT
each Chapter gives you much more information if you have read the previous chapter.
The KEY KEY Chapter are:
a)Scenegraph
b) Message and Task