How to use the OnscreenText to show the game state?

Hi all~ I’m a newbie in using panda3d and python.

I’m using Tut-Labyrinth.py which is in “Feature tutorials”, “Collision-Detection” and try to show the game state by OnscreenText.

I added Onscreen text in “def loseGame”.

def loseGame(self, entry):
toPos = entry.getInteriorPoint(render)
taskMgr.remove(‘rollTask’) #Stop the maze task
self.loseLabel=OnscreenText(text=“You Lose”,
style=1, fg=(1,1,1,1),
pos=(0.0,0.0), scale = .07)
Sequence(
Parallel(
LerpFunc(self.ballRoot.setX, fromData = self.ballRoot.getX(),
toData = toPos.getX(), duration = .1),
LerpFunc(self.ballRoot.setY, fromData = self.ballRoot.getY(),
toData = toPos.getY(), duration = .1),
LerpFunc(self.ballRoot.setZ, fromData = self.ballRoot.getZ(),
toData = self.ballRoot.getZ() - .9, duration = .2)),
Wait(1),
Func(self.start)).start()

the OnscreenText is showed when the balll fall in the hole but it doesn’t remove when it start again.

How to fix that?

Try this:

  def loseGame(self, entry):
    toPos = entry.getInteriorPoint(render)
    taskMgr.remove('rollTask')  #Stop the maze task
    self.loseLabel=OnscreenText(text="You Lose",
                              style=1, fg=(1,1,1,1),
                              pos=(0.0,0.0), scale = .07)
     Sequence(
      Parallel(
      LerpFunc(self.ballRoot.setX, fromData = self.ballRoot.getX(),
               toData = toPos.getX(), duration = .1),
      LerpFunc(self.ballRoot.setY, fromData = self.ballRoot.getY(),
               toData = toPos.getY(), duration = .1),
      LerpFunc(self.ballRoot.setZ, fromData = self.ballRoot.getZ(),
               toData = self.ballRoot.getZ() - .9, duration = .2)),
      Wait(1),
      Func(self.loseLabel.destroy),
      Func(self.start)).start()

You see in the interval I added a function call to self.loseLabel.destroy(), right before the start() function is executed.

thks!
u are very helpful :smiley: