[英]Maximum recursion depth exceeded when creating subclass of pygame.sprite.Sprite
我正在尝试实例化我创建的对象女巫是 pygame.sprite.Sprite 的子类。 这是我用来实例化它的代码:
import pygame as pg
from GameObject import GameObject
player = GameObject("Sprites/Player", 6)
这是对象本身的代码:
import pygame as pg
class GameObject(pg.sprite.Sprite):
def __ini__(self, image_path, number_of_images):
for i in range(number_of_images):
self.images.append(pg.image.load("{}/sprite{}.png".format(image_path, i)))
当我尝试运行它时,我得到了这个:
Traceback (most recent call last):
File "main.py", line 11, in <module>
player = GameObject("Sprites/Player", 6)
File "/usr/lib/python3.6/site-packages/pygame/sprite.py", line 124, in __init__
self.add(*groups)
File "/usr/lib/python3.6/site-packages/pygame/sprite.py", line 142, in add
self.add(*group)
File "/usr/lib/python3.6/site-packages/pygame/sprite.py", line 142, in add
self.add(*group)
File "/usr/lib/python3.6/site-packages/pygame/sprite.py", line 142, in add
self.add(*group)
[Previous line repeated 327 more times]
RecursionError: maximum recursion depth exceeded
我已经查看了用于创建此类的子类的服务器示例代码,但我没有看到我的代码与其他代码之间的区别。 我错过了什么?
我有同样的问题,它是由__init__
(你写__ini__
)函数中的错字引起的(当我写_init_
而不是__init__
时发生在我身上)。 修复错字使它起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.