I'm making a game and I have almost finished it, but I'm usually finding the error
RuntimeError: maximum recursion depth exceeded when I iterate a sprite group.
This is an example and the group is
def nextStageCollision(self): for tile in self.nextStageCollision(): if tile.rect.colliderect(self.rect): self.rect.x = 18*20 self.rect.y = 20*20 return True return False
self.nextStageCollision() has 4 sprites (tiles) and I'm checking collision between my player and those 4 tiles to go to the next stage but I have to be doing something wrong iterating the sprite group because (I don't know why) it becomes recursive and raises the maximum recursion depth runtime error. I've debugged it and when it reaches the
for each line, it loops a lot of times there (althought there are only 4 sprites in that group).
I know I can increase the recursion depth, but probably it's better to not play with that and try to improve the code. So, what am I doing wrong? Is there another better way to interate a sprite group to check collisions?