我正在尝试实现一个我创建的对象女巫是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
我已经查看了用于创建此类的子类的服务器示例代码,但我没有看到我的代码与其他代码之间的区别。我错过了什么?
答案 0 :(得分:0)
我遇到了同样的问题,这是由__init__
(您写了__ini__
)函数中的错字引起的(我写_init_
而不是{{1}时碰到了我})。
修正错字使它起作用