我的游戏代码是一款简单的平台游戏,但是当我尝试添加精灵时,RecursionError: maximum recursion depth exceeded while calling a Python object
出现了错误
我遵循一个粗略的教程,并尝试修改自己的代码,我是相当新的编码,所以谁能帮助解决这个问题?
我见过有人把递归变成一个循环,我不明白这是什么。
class Enemy(pygame.sprite.Sprite()):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('image/spida.png')
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
这里是给我一个错误的代码块,具体部分是pygame.sprite.Sprite.__init__(self)
,它突出显示self
部分,说Expected type 'Sprite', got 'Enemy' instead
(这是在项目错误部分的代码)
您的代码中有一个错别字pygame.sprite.Sprite()
创建一个新的实例对象。变化:
class Enemy(pygame.sprite.Sprite())
:
class Enemy(pygame.sprite.Sprite)