2014-09-22 301 views
0

所以,我使用这个类在我的游戏:我创建了这个类pygame.sprite.Sprite.kill()无法正常工作。为什么?

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() 

后,我做了这个类的一个项目。然后我打电话的更新功能:

magazine = Magazine(magazineImage, forry) 
magazine.update() 

出于某种原因,我得到这个错误:

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' 

回答

1

好了,所有你需要做的是,如果你要使用附带的功能精灵类,你首先必须插入:

super(spritename, self).init() 

因此,对于这个,你需要插入:

super(Magazine, self).init() 

进入你的init函数。

相关问题