Reputation: 51
So, I use this class in my game:
class Magazine(pygame.sprite.Sprite):
def __init__(self, image, shooter):
self.image = image
self.rect = image.get_rect()
self.rect.x = shooter.rect.x
self.rect.y = shooter.rect.y - shooter.image.get_height()
def update(self):
self.rect.y -= 5
if self.rect.y <= 0 - self.image.get_height():
self.kill()
After I created this class, I made an item of that class. Then I called its update function:
magazine = Magazine(magazineImage, forry)
magazine.update()
For some reason I get this error:
Traceback (most recent call last):
File "main.py", line 106, in <module>
main()
File "main.py", line 78, in main
projectileObject.update()
File "/Users/number1son100/Desktop/Famous Monsters Game/gameobjects.py", line 117, in update
self.kill()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/sprite.py", line 174, in kill
for c in self.__g.keys():
AttributeError: 'Magazine' object has no attribute '_Sprite__g'
Upvotes: 0
Views: 862
Reputation: 51
Ok, so all you need to do is, if you are going to use the functions that come with the sprite class, you first have to insert:
super(spritename, self).init()
So for this you need to insert:
super(Magazine, self).init()
into your init function.
Upvotes: 1