衍生类失踪论证:' self'

时间:2017-05-05 01:00:28

标签: python pygame

我需要将派生类合并到我的游戏中,但是当我更新课程时,它会说

  

TypeError:update()缺少1个必需的位置参数:' self'

尝试转动(有效)

class Rain(pygame.sprite.Sprite):
    def __init__(self,x,image):
        pygame.sprite.Sprite.__init__(self)
        self.image = image
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = 0
    def update(self):
        self.rect.bottom += 5

class BadRain(pygame.sprite.Sprite):
    def __init__(self,x,image):
        pygame.sprite.Sprite.__init__(self)
        self.image = image
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = 0
    def update(self):
        self.rect.bottom += 5

进入不起作用的

class Rain():
    def __init__(self,x,image):
        self.image = image
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = 0

class Bad(pygame.sprite.Sprite):
    def __init__(self,x,image):
        Rain.__init__(self,x,image)
        pygame.sprite.Sprite.__init__(self)
        self.rect = self.image.get_rect()
    def update(self):
        self.rect.bottom += 5

class Good(pygame.sprite.Sprite):
    def __init__(self,x,image):
        Rain.__init__(self,x,image)
        pygame.sprite.Sprite.__init__(self)
        self.rect = self.image.get_rect()
    def update(self):
        self.rect.bottom += 5

1 个答案:

答案 0 :(得分:0)

我解决了问题

class Rain(pygame.sprite.Sprite):
    def __init__(self,x,image):
        self.image = image
        self.rect = self.image.get_rect()
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = 0

class Bad(Rain):
    def __init__(self,x,image):
        Rain.__init__(self,x,image)
        pygame.sprite.Sprite.__init__(self)
        self.rect = self.image.get_rect()
    def update(self):
        self.rect.bottom += 5

class Good(Rain):
    def __init__(self,x,image):
        Rain.__init__(self,x,image)
        pygame.sprite.Sprite.__init__(self)
    def update(self):
        self.rect.bottom += 5