I have again stumbled across a problem in my Pygame project. In trying to create a group for my platforms, which will aid in coding environmental collision, I am getting the error:
'Platform' object has no attribute 'add_internal'
I have created a group:
platforms=pygame.sprite.Group()
ground=GameClass.Platform(0,500,500,40)
platforms.add(ground)
The ground variable is assigned to the class 'Platform' in the separate file 'GameClass':
class Platform:
def __init__(self,x,y,w,h):
self._x=x
self._y=y
self._w=w
self._h=h
pygame.draw.rect(display,BLACK,[self._x,self._y,self._w,self._h])
The group creation code resides above the game loop, so it is only run once.
Thanks, Link
You can only add instances of pygame.sprite.Sprite subclasses to a pygame.sprite.Group. You also have to call the __init__ method of the superclass: super().__init__() (or super(Platform, self).__init__() in Python 2).
class Platform(pygame.sprite.Sprite):
def __init__(self,x,y,w,h):
super().__init__()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With