【发布时间】:2017-08-09 13:26:00
【问题描述】:
我在我的游戏中处理动画,但我遇到了一个错误..你能帮帮我吗?)
或者我需要添加我的所有代码吗?
class Animation:
def __init__(self, x, y, sprites=None, time=100):
self.x = x
self.y = y
self.sprites = sprites
self.time = time
self.work_time = 0
self.skip_frame = 0
self.frame = 0
def update(self, dt):
self.work_time += dt
self.skip_frame = self.work_time // self.time
if self.skip_frame > 0:
self.work_time = self.work_time % self.time
self.frame += self.skip_frame
if self.frame >= len(self.sprites):
self.frame = 0
def get_sprite(self):
return self.sprites[self.frame]
Traceback (most recent call last):
File "C:\Users\Zyzz\Desktop\game\bin.py", line 210, in <module>
target.update(dt)
File "C:\Users\Zyzz\Desktop\game\bin.py", line 98, in update
self.skip_frame = self.work_time // self.time
TypeError: unsupported operand type(s) for //: 'int' and 'module'
【问题讨论】:
-
这与你如何调用
Animation(..)构造函数有关。 -
我需要更改构造函数的名称吗?
-
Noo... 这就是它们的名称。使用
time参数... -
不,您需要更改实例化它们的方式。当您创建
Animation时,您传递的time是什么?那就是错误所抱怨的module,无论Python版本如何,它都会发生。当然,由于代码中其他地方的原因,Python 3 传递了一个module,而 Python 2 传递了一个int,这可能会发生。
标签: python python-3.x python-2.x code-conversion