本文整理汇总了Python中panda3d.core.TextNode.appendText方法的典型用法代码示例。如果您正苦于以下问题:Python TextNode.appendText方法的具体用法?Python TextNode.appendText怎么用?Python TextNode.appendText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.TextNode
的用法示例。
在下文中一共展示了TextNode.appendText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessageWriter
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import appendText [as 别名]
class MessageWriter(DirectObject):
def __init__(self):
# the tasktime the last sign in the textfield was written
self.lastSign = 0.0
# the sign that is actually written in the textfield
self.currentSign = 0
# the text to write in the textfield
self.textfieldText = ""
# stop will be used to check if the writing is finished or
# somehow else stoped
self.stop = False
# the speed new letters are added to the text
# the time, how long the text is shown after it is fully written
self.showlength = 4
# the textfield to put instructions hints and everything else, that
# should be slowly written on screen and disappear after a short while
self.textfield = TextNode('textfield')
self.textfield.clearText()
self.textfield.setShadow(0.005, 0.005)
self.textfield.setShadowColor(0, 0, 0, 1)
self.textfield.setWordwrap(base.a2dRight*2-0.4)
self.textfield.setCardActual(
-0.1, base.a2dRight*2-0.3,
0.1, base.a2dBottom+0.5)
self.textfield.setCardColor(0,0,0,0.45)
self.textfield.setFlattenFlags(TextNode.FF_none)
self.textfield.setTextScale(0.06)
self.textfieldNodePath = aspect2d.attachNewNode(self.textfield)
self.textfieldNodePath.setScale(1)
self.textfieldNodePath.setPos(base.a2dLeft+0.2, 0, -0.4)
self.hide()
def show(self):
self.textfieldNodePath.show()
def hide(self):
self.textfield.clearText()
self.textfieldNodePath.hide()
def clear(self):
"""Clear the textfield and stop the current written text"""
self.hide()
taskMgr.remove("writeText")
self.stop = False
self.writeDone = False
self.currentSign = 0
self.lastSign = 0.0
self.textfield.clearText()
def cleanup(self):
"""Function that should be called to remove and reset the
message writer"""
self.clear()
self.ignore("showMessage")
def run(self):
"""This function can be called to start the writer task."""
self.textfield.setFlattenFlags(TextNode.FF_none)
taskMgr.add(self.__writeText, "writeText", priority=30)
def setMessageAndShow(self, message):
"""Function to simply add a new message and show it if no other
message is currently shown"""
self.clear()
logging.debug("show message %s" % message)
self.textfieldText = message
self.show()
# start the writer task
self.run()
def __writeText(self, task):
elapsed = globalClock.getDt()
if(self.stop):
# text is finished and can be cleared now
self.clear()
return task.done
if self.currentSign == len(self.textfieldText)-1:
self.textfield.setFlattenFlags(TextNode.FF_dynamic_merge)
if self.currentSign >= len(self.textfieldText):
# check if the text is fully written
if task.time - self.lastSign >= self.showlength:
# now also check if the time the text should
# be visible on screen has elapsed
self.stop = True
self.textfieldNodePath.flattenStrong()
elif (task.time - self.lastSign > base.textWriteSpeed) and (not self.stop):
# write the next letter of the text
self.textfield.appendText(self.textfieldText[self.currentSign])
self.currentSign += 1
self.lastSign = task.time
return task.cont