[英]Why pygame.sprite causes “maximum recursion depth” in my class?
我做了这个简单的类,但由于某种原因它使 python 崩溃,我不知道为什么
这是代码
import pygame
pygame.init()
class Entity(pygame.sprite.Sprite()):
def __init__(self, pos, size):
super().__init__()
这是我得到的错误
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "entity.py", line 4, in <module>
class Entity(pygame.sprite.Sprite()):
File "C:\Users\playe\AppData\Local\Programs\Python\Python38\lib\site-packages\pygame\sprite.py", line 124, in __init__
self.add(*groups)
File "C:\Users\playe\AppData\Local\Programs\Python\Python38\lib\site-packages\pygame\sprite.py", line 142, in add
self.add(*group)
File "C:\Users\playe\AppData\Local\Programs\Python\Python38\lib\site-packages\pygame\sprite.py", line 142, in add
self.add(*group)
File "C:\Users\playe\AppData\Local\Programs\Python\Python38\lib\site-packages\pygame\sprite.py", line 142, in add
self.add(*group)
[Previous line repeated 992 more times]
File "C:\Users\playe\AppData\Local\Programs\Python\Python38\lib\site-packages\pygame\sprite.py", line 137, in add
if hasattr(group, '_spritegroup'):
RecursionError: maximum recursion depth exceeded while calling a Python object
我该如何纠正这个错误?
pygame.sprite.Sprite()
创建一个对象。 对于基类,您只需要指定类的名称。 请参阅继承。
将pygame.sprite.Sprite()
更改为pygame.sprite.Sprite
class Entity(pygame.sprite.Sprite()):
class Entity(pygame.sprite.Sprite):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.