[英]Why pygame.sprite causes “maximum recursion depth” in my class?
I made this simple class and for some reason it crashes python and I dont know why我做了这个简单的类,但由于某种原因它使 python 崩溃,我不知道为什么
This is the code这是代码
import pygame
pygame.init()
class Entity(pygame.sprite.Sprite()):
def __init__(self, pos, size):
super().__init__()
and this is the error I get这是我得到的错误
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
How can I correct this error?我该如何纠正这个错误?
pygame.sprite.Sprite()
creates an object. pygame.sprite.Sprite()
创建一个对象。 For the base class, you only need to specify the name of the class.对于基类,您只需要指定类的名称。 See Inheritance .请参阅继承。
Change pygame.sprite.Sprite()
to 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.