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
x
andy
arguments to yourKunai()
class. What did you hopeKunai()
do without values for your two parameters?