문제

Having a real struggle getting this sorted. Had look at some other answers, and I get an error saying that I have too many arguments.

Class containing the objects I want to add.

class Digimon(pygame.sprite.Sprite):
    def __init__(self,age,weight,strength,defence,speed,intelligence, image):
        self.age = age
        self.weight = weight
        self.strength = strength
        self.defence = defence
        self.speed = speed
        self.intelligence = intelligence
        self.image = image

Have tried to do:

class Digimon(pygame.sprite.Sprite):
    def __init__(self):
    pygame.sprite.Sprite.__init__(self,age,weight,strength,defence,speed,intelligence, image)
    self.age = age  
    self.weight = weight    
    self.strength = strength 
    self.defence = defence  
    self.speed = speed  
    self.intelligence = intelligence 
    self.image = image

but I error regarding the amount of arguments. (1 given, 7 needed).

Player = Digimon(0,2,0,0,0,0, [pygame.image.load("images/koro_1.png"), pygame.image.load("images/koro_2.png"), pygame.image.load("images/koro_3.png") ] ) 

This is in example of an object which I want to group together. From this, I'll be able to add keyboard events which affect all the objects grouped.

Any help would be fantastic :D

edit: full code: http://pastebin.com/uPWEM8bD

도움이 되었습니까?

해결책

pygame.sprite.Sprite.__init__(self,age,weight,strength,defence,speed,intelligence, image)

The base Sprite class has no need for your age/weight/etc variables. Just pass in self:

pygame.sprite.Sprite.__init__(self)

다른 팁

You have 8 arguments (7 number variables and an image) in the definition but when you call it you pass 7 (6 ints and a list of images).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top