I have been trying to make a game, but mask collision doesn't seem to work. Here is my code:
class Player(pg.sprite.Sprite):
def ___init__(self, game, x, y, lvl):
self.group = game.all_sprites
pg.sprite.Sprite.__init__(self.groups)
#nothing else important
def update(self):
self.mask = pg.mask.from_surface(self.image)
#check if hits
hits = pg.sprite.spritecollide(self, self.game.kill, False, pg.sprite.collide_mask)
if hits:
#stops game
self.game.playing = False
class Kill(pg.sprite.Sprite):
def ___init__(self, game, x, y, lvl):
self.group = game.kill
pg.sprite.Sprite.__init__(self.groups)
def update(self):
self.mask = pg.mask.from_surface(self.image)
The problem is that the game sets self.game.playing to False even before the pixels collide.
__init__
, that means the__init__
methods won't be called during the instantiation (the code shouldn't work at all because of this typo). Please elaborate the question. \$\endgroup\$