Why isn't this code working? I'm trying to create a class to quickly create players for my game in pygame. I was trying to create a sprite based on what he did in this video, https://www.youtube.com/watch?v=hDu8mcAlY4E, and his seemed to work fine.
class Player(Sprite):
def __init__(self,x,y,picture_path,width,height):
super().__init__()
self.image = pygame.image.load(picture_path)
self.rect = self.image.get_rect()
def move(self):
self.x += self.dx
self.y += self.dy
self.dy += GRAVITY
def jump(self):
self.dy -= 15
def left(self):
self.dx -= 6
if self.dx < -12:
self.dx = -12
def right(self):
self.dx = 6
if self.dx > 12:
self.dx = 12
player = Player(600,0,'nin.png',20,20)
player2 = Player(600,40,'nin.png',20,20)
If you want the error for this here it is;
Traceback (most recent call last):
File "main.py", line 107, in <module>
player = Player(600,0,'nin.png',20,20)
File "main.py", line 77, in __init__
super().__init__()
TypeError: __init__() missing 4 required positional arguments: 'x', 'y', 'width', and 'height'
Traceback (most recent call last):
File "main.py", line 107, in <module>
player = Player(600,0,'nin.png',20,20)
File "main.py", line 77, in __init__
super().__init__()
TypeError: __init__() missing 4 required positional arguments: 'x', 'y', 'width', and 'height'
repl.it/@Rabbid76/PyGame-Sprite