0

When I run this bit of code, it says that I have an error:

TypeError: __init__() missing 2 required positional arguments: 'x' and 'y'

I call the class and added them to a group:

kunai = Kunai()
kunai_sprites = pg.sprite.Group() #puts all the kunai sprites into a group

Here is the class:

#throwing projectile (kunai)
class Kunai(pg.sprite.Sprite): #creating the kunai class
    def __init__(self, x, y): #initialising the kunai
        pg.sprite.Sprite.__init__(self)
        self.image = pg.Surface((10,20))
        self.image.fill(RED)
        self.velocity = 35
        self.rect = self.image.get_rect()
        self.rect.bottom = y
        self.rect.centrex = x

#drawing a circle which will determine the throwing range of the kunai
    def update(self):
        self.rect.y = self.rect.y + self.velocity #the kunai moves at set speed
        if self.rect.bottom < 0: #if the sprite crosses 
            self.kill() #it removes the sprite
2
  • 4
    Your own code doesn't pass in any x and y arguments to your Kunai() class. What did you hope Kunai() do without values for your two parameters?
    – Martijn Pieters
    Feb 4, 2020 at 16:09
  • Since the issue is trivial, basic, and straightforward, I’m voting to close this under typo/can’t be reproduced.
    – AMC
    Feb 5, 2020 at 3:08

1 Answer 1

6

You need to do.

kunai = Kunai(x,y)

Like the error says, you are missing two arguments in your initialization.

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.