本文整理汇总了Python中panda3d.core.TextNode.setTextScale方法的典型用法代码示例。如果您正苦于以下问题:Python TextNode.setTextScale方法的具体用法?Python TextNode.setTextScale怎么用?Python TextNode.setTextScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.TextNode
的用法示例。
在下文中一共展示了TextNode.setTextScale方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addAvatar
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setTextScale [as 别名]
def addAvatar(self, avId, name, damage):
if self.currentIndex == 0:
self.addLeaderboardLabel()
self.avId2Names[avId] = name
self.avId2Damage[avId] = damage
text = TextNode('leaderboard-%d' % avId)
text.setAlign(TextNode.ACenter)
text.setFlattenFlags(TextNode.FFMedium)
text.setFont(getSuitFont())
text.setTextScale(0.05)
text.setTextColor(*TEXT_WHITE)
text.setText(name + ': ' + str(damage))
textNodePath = aspect2d.attachNewNode(text)
textNodePath.reparentTo(base.a2dTopRight)
if self.currentIndex:
self.index2Pos[self.currentIndex] = (-0.35, 0.0, (TEXT_HEIGHT * self.currentIndex) - 0.1)
textNodePath.setPos(*self.index2Pos[self.currentIndex])
else:
self.index2Pos[0] = (-0.35, 0.0, -0.20)
textNodePath.setPos(*self.index2Pos[0])
self.currentIndex += 1
self.avId2Nodes[avId] = [textNodePath, text]
示例2: appendStoredText
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setTextScale [as 别名]
def appendStoredText(self,textprops, speed = 0, fadein = 0, fadeinType = 0):
#append a text stored with appendText() or by loading self.recordedText
text = textprops['text']
newLine = textprops['newLine']
custom = textprops['custom']
if custom:
textMaker = TextNode('temptextmaker', self.textMaker)
font = textprops['font']
if font:
textMaker.setFont(font)
textScale = textprops['textScale']
if textScale:
textMaker.setTextScale(textScale)
fg = textprops['fg']
if fg:
self.setFg(fg, textMaker)
shadow = textprops['shadow']
shadowOffset = textprops['shadowOffset']
if shadow:
self.setShadow(shadow, shadowOffset, textMaker)
#prepared to add more props here
else: textMaker = self.textMaker
if newLine or not self.lines:
self.startLine()
if not speed:
for word in text:
self.appendWord(word, tm = textMaker, fadein = fadein, fadeinType = fadeinType)
#TYPER EFFECT
else:
self.__TextLerpInit()
self.__currentLerpInterval = LerpFunc(self._appendTextLerpFunc,extraArgs = [text,textMaker,fadein,fadeinType],
duration = len(text)/float(speed))
self.__currentLerpInterval.start()
示例3: MessageWriter
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setTextScale [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
示例4: __init__
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setTextScale [as 别名]
class BossBattleLeaderboard:
def __init__(self):
self.avId2Names = {}
self.avId2Nodes = {}
self.avId2Damage = {}
self.avId2FlashTrack = {}
self.index2Pos = {}
self.currentIndex = 0
self.leaderboardLabel = None
self.leaderboardLabelNP = None
self.isSorting = False
def load(self):
pass
def hasAvatar(self, avId):
return avId in self.avId2Names.keys()
def addLeaderboardLabel(self):
self.leaderboardLabel = TextNode('leaderboardLabel')
self.leaderboardLabel.setAlign(TextNode.ACenter)
self.leaderboardLabel.setFlattenFlags(TextNode.FFMedium)
self.leaderboardLabel.setFont(getSuitFont())
self.leaderboardLabel.setTextScale(0.075)
self.leaderboardLabel.setTextColor(*TEXT_WHITE)
self.leaderboardLabel.setText(BossLeaderboardLabel)
self.leaderboardLabelNP = aspect2d.attachNewNode(self.leaderboardLabel)
self.leaderboardLabelNP.reparentTo(base.a2dTopRight)
self.leaderboardLabelNP.setPos(-0.35, 0.0, -0.1)
def makeFlashTrack(self, tNode, damage):
return Track(
(0.25, Func(tNode.setTextColor, *TEXT_GREEN)),
(0.50, Func(tNode.setTextColor, *TEXT_WHITE)),
(0.50, Func(tNode.setText, damage)),
(0.75, Func(tNode.setTextColor, *TEXT_GREEN)),
(1.0, Func(tNode.setTextColor, *TEXT_WHITE)),
(1.25, Func(tNode.setTextColor, *TEXT_GREEN)),
(1.50, Func(tNode.setTextColor, *TEXT_WHITE)),
(1.75, Func(tNode.setTextColor, *TEXT_GREEN)),
(2.0, Func(tNode.setTextColor, *TEXT_WHITE)),
)
def addAvatar(self, avId, name, damage):
if self.currentIndex == 0:
self.addLeaderboardLabel()
self.avId2Names[avId] = name
self.avId2Damage[avId] = damage
text = TextNode('leaderboard-%d' % avId)
text.setAlign(TextNode.ACenter)
text.setFlattenFlags(TextNode.FFMedium)
text.setFont(getSuitFont())
text.setTextScale(0.05)
text.setTextColor(*TEXT_WHITE)
text.setText(name + ': ' + str(damage))
textNodePath = aspect2d.attachNewNode(text)
textNodePath.reparentTo(base.a2dTopRight)
if self.currentIndex:
self.index2Pos[self.currentIndex] = (-0.35, 0.0, (TEXT_HEIGHT * self.currentIndex) - 0.1)
textNodePath.setPos(*self.index2Pos[self.currentIndex])
else:
self.index2Pos[0] = (-0.35, 0.0, -0.20)
textNodePath.setPos(*self.index2Pos[0])
self.currentIndex += 1
self.avId2Nodes[avId] = [textNodePath, text]
def updateAvatar(self, avId, damage):
if avId in self.avId2Nodes and avId in self.avId2Names:
self.avId2Damage[avId] = self.avId2Damage[avId] + damage
if avId in self.avId2FlashTrack:
if self.avId2FlashTrack[avId].isPlaying():
self.avId2FlashTrack[avId].finish()
damageString = self.avId2Names[avId] + ': ' + str(self.avId2Damage[avId])
flashTrack = self.makeFlashTrack(self.avId2Nodes[avId][1], damageString)
flashTrack.start()
self.avId2FlashTrack[avId] = flashTrack
self.sortLeaderboard()
def sortLeaderboard(self):
if not self.isSorting:
self.isSorting = True
for avId in self.avId2Nodes:
self.avId2Nodes[avId][0].hide()
sortedTuples = sorted(self.avId2Damage.items(), key=operator.itemgetter(1), reverse=True)
sortedAvIds = [data[0] for data in sortedTuples]
for avId in self.avId2Nodes:
self.avId2Nodes[avId][0].setPos(*self.index2Pos[sortedAvIds.index(avId)])
for avId in self.avId2Nodes:
self.avId2Nodes[avId][0].show()
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setTextScale [as 别名]
class BossBattleTimer:
def __init__(self):
self.text = None
self.textNodePath = None
self.flashTrack = None
self.textSequence = None
self.startTime = 0
self.endTime = 0
def load(self):
self.text = TextNode('BossBattleTimer')
self.text.setAlign(TextNode.ACenter)
self.text.setFlattenFlags(TextNode.FFMedium)
self.text.setFont(getSuitFont())
self.text.setTextScale(0.075)
self.text.setTextColor(*TEXT_WHITE)
self.textNodePath = aspect2d.attachNewNode(self.text)
self.textNodePath.reparentTo(base.a2dBottomLeft)
self.textNodePath.setPos(0.60, 0.0, 0.15)
def makeFlashTrack(self):
return Track(
(0.25, Func(self.text.setTextColor, *TEXT_GREEN)),
(0.50, Func(self.text.setTextColor, *TEXT_WHITE)),
(0.75, Func(self.text.setTextColor, *TEXT_GREEN)),
(1.0, Func(self.text.setTextColor, *TEXT_WHITE)),
(1.25, Func(self.text.setTextColor, *TEXT_GREEN)),
(1.50, Func(self.text.setTextColor, *TEXT_WHITE)),
(1.75, Func(self.text.setTextColor, *TEXT_GREEN)),
(2.0, Func(self.text.setTextColor, *TEXT_WHITE)),
)
def makeGrowShrinkSequence(self):
return Sequence(
LerpScaleInterval(self.textNodePath, duration=2.0, scale=1.1, startScale=0.9),
LerpScaleInterval(self.textNodePath, duration=2.0, scale=0.9, startScale=1.1),
)
def destroy(self):
if self.flashTrack:
self.flashTrack.finish()
self.flashTrack = None
if self.textSequence:
self.textSequence.finish()
self.textSequence = None
if self.text:
self.text.setText('')
if self.textNodePath:
self.textNodePath.removeNode()
def start(self, startTime):
self.startTime = startTime
self.endTime = 0
if self.textNodePath:
taskMgr.doMethodLater(0.05, self.updateText, 'updateBossText-%s' % self.startTime)
self.textSequence = self.makeGrowShrinkSequence()
self.textSequence.loop()
def updateText(self, task=None):
self.text.setText(str(round(time() - self.startTime, 3)) + ' seconds')
if self.endTime != 0:
return Task.done
return Task.again
def stop(self, endTime):
self.endTime = endTime
taskMgr.remove('updateBossText-%s' % self.startTime)
if self.textNodePath:
self.text.setText(str(round(self.endTime - self.startTime, 3)) + ' seconds')
self.flashTrack = self.makeFlashTrack()
self.flashTrack.start()