我在python/pygame中編程的遊戲中有一個計時器。減少在python中的時間
定時器工作正常,當我在主類的一切:
time=50
seconds_passed = clock.tick()/1000.0
time-=seconds
draw_time=math.tranc(time)
print(draw_time)
然而,當我移動到一個新的類球員
class player():
.
.
.
set_time(self, draw_time):
seconds_passed = clock.tick()/1000.0
time-=seconds_passed
draw_time=math.tranc(time)
print(draw_time)
這個當我調用主類此功能:
class main():
.
.
.
draw_time=20
player = Player()
print player.set_time(draw_time)
我的時間不是遞減,而是保持不變!
有什麼建議嗎?
的可能重複[爲什麼能在蟒紋變量函數在封閉的範圍,但在分配不能使用它們?(http://stackoverflow.com/questions/18864041/why-can-functions-in-python -print-variables-in-enclosing-scope-but-can-use-th) – fjarri
什麼是'seconds',它與'seconds_passed'的關係是什麼? – tripleee
對不起的錯字,固定編輯 –