Text with time panda3d python

I want to print text for 15 seconds. I printed text with text node, but it appears constantly. How can I do this with the timer?

Edit:

Thanks for changing the section of the thread.

I fixed it. I am sorry about it.

It’s no problem!

Back to your question:

To clarify what it is you are trying to achieve, are you wishing for text to only appear for 15 seconds? If so, it seems it would be easiest to define a function that changes the TextNode to a null string like " " upon a certain condition like a bool changing.

This could happen upon something changing the bool in your program’s logic, or by a sleep-timer in a thread using Python’s built-in time.sleep(seconds).

Or even a call to the task-manager’s “doMethodLater” method.

You can also use Intervals for this. In particular, you can use a function interval to run logic to remove the text node. Here is an example of using intervals to display damage values.

1 Like

Or another implementation using async :

from direct.task import Task
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.ShowBase import ShowBase

async def timed_text(parent, text):
    node = OnscreenText(text=text, parent=parent, fg=(1, 1, 1, 1))
    await Task.pause(2)
    node.destroy()

base = ShowBase()
taskMgr.add(timed_text(base.render2dp, "Hello world!"))
base.run()
2 Likes