我在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
对不起的错字,固定编辑 –