我試圖遍歷元組的陣列(在恆定形式):「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