我是Python的新手。我正在使用Vizard 4.0创建一个简单的3D世界,我想在屏幕上添加一个秒表。我不想要一个真正的3D秒表,只是屏幕一角的一个简单的文本框,随着秒表计数而更新。继续我到目前为止,它不起作用,任何建议或帮助将非常感激!
def mytimer(num):
time = 'Elapsed time:',viz.elapsed(),'seconds'
print time
timer_update = viz.addText('Time:', viz.SCREEN)
timer_update.color(viz.GREEN)
timer_update.fontSize(42)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,1, viz.FOREVER)
答案 0 :(得分:0)
破解它:)
#Add text fields to a dictionary.
text_dict = {}
for kind in ['score','instructions','time' ]:
text = viz.addText('', viz.SCREEN )
text.setScale( .5,.5)
text.alignment( viz.TEXT_CENTER_BASE )
text.alpha( 1 )
text_dict[ kind ] = text
text_dict['score'].setPosition( .1,.9 )
text_dict['instructions'].setPosition( .5,.5 )
text_dict['time'].setPosition( .1,.85 )
def game_timer_task():
#Grab the text field for
#time.
text = text_dict[ 'time' ]
time = 0
text.message( 'Time: 0' )
#Loop through as long as time
#is under a certain number of
#seconds.
while time < 10:
yield viztask.waitTime( 1 )
time += 1
text.message( 'Time: ' + str( time ) )
def game():
time_passing = viztask.waitTask( game_timer_task() )
data = viz.Data()
yield viztask.waitAny( [time_passing], data )
if data.condition == time_passing:
game_over = text.message( 'Game Over!' )
game_over.setPosition( .1,.85 )
def main_sequence():
yield game()
viztask.schedule( main_sequence() )