我试图遍历元组的阵列(在恒定形式):“NoneType”对象不是可迭代
SPRITE_RIGHT = [(0, 0), (16, 0), (32, 0)]
SPRITE_LEFT = [(0, 16), (16, 16), (32, 0)]
SPRITE_UP = [(0, 32), (16, 32), (32, 0)]
SPRITE_DOWN = [(0, 48), (16, 48), (32, 0)]
def symbol(self):
self._status += 1
if (self._status > 2):
self._status = 0
if (self._dx > 0):
(x, y) = PacMan.SPRITE_RIGHT[self._status]
return (x,y)
if (self._dx < 0):
(x, y) = PacMan.SPRITE_LEFT[self._status]
return (x,y)
if (self._dy > 0):
(x, y) = PacMan.SPRITE_DOWN[self._status]
return (x,y)
if (self._dy < 0):
(x, y) = PacMan.SPRITE_UP[self._status]
return (x,y)
...
for a in arena.actors():
if not isinstance(a, Wall):
x, y, w, h = a.rect()
xs, ys = a.symbol() #This line gives me the problem
screen.blit(sprites, (x, y), area=(xs, ys, w, h))
当我执行该程序我收到此错误:
TypeError: 'NoneType' object is not iterable
对于每一个演员我调用该方法符号()来获取其图像
When i print PacMan.SPRITE_UP[0] for example it returns the correct tuple
您发布的代码似乎是正确的,假设'self._status'的合理值。也许你省略了太多。你可以尝试做一个最小的工作示例,执行时仍显示错误吗? – Joost
x,y = None @Joost – palsch
所以SPRITE_RIGHT [self._status]是无 – palsch