Reputation: 53
I'm using pygame
and have created a class called Entity
and a Subclass Player
. The class Entity requires an argument "pos", which is always just "pos", because the value for it is created in the init.
class Entity(pygame.sprite.Sprite):
def __init__(self, color, stype, pos, *groups):
super().__init__(*groups)
self.image = stype
try:
self.image.fill(color)
except:
pass
self.image.convert()
self.rect = self.image.get_rect(topleft=pos)
def update(self, dt, events):
pass
class Player(Entity):
def __init__(self, platforms, pos, *groups):
super().__init__((pygame.image.load("lemon.png")), pos)
self.vel = pygame.Vector2((0, 0))
self.onGround = False
self.platforms = platforms
self.speed = 8
self.jump_strength = 10
However when I try to run the code it gives me this error:
TypeError: init() missing 1 required positional argument: 'pos'
Upvotes: 2
Views: 80
Reputation: 4487
Why only two arguments pass here:
super().__init__((pygame.image.load("lemon.png")), pos)
But the constructor of Entity
requires at least 3:
def __init__(self, color, stype, pos, *groups)
I don't know your problem well, but this could be a solution:
super().__init__(color=None, stype=(pygame.image.load("lemon.png")), pos=pos)
Upvotes: 4