Jan-22-2020, 02:39 AM
I ran into some problems. If I leave the "kill" part of the collision at
Here is the latest version that I put in the Platform._init_. Works great at first but lags after a while and lags when the player gets a powerup and zips up really fast:
Here is the kill code for when the player falls to his death. This is when the game freezes and eventually runs out of memory:
False
, the sprites piled up at the top of the screen and eventually gave huge lag. So I changed it and have tried every collision type and way of killing sprites because what happens is that when the player falls and is supposed to die, the game slows to a halt and eventually gives a Error:pygame ERROR: out of memory.
I don't know what is piling up.Here is the latest version that I put in the Platform._init_. Works great at first but lags after a while and lags when the player gets a powerup and zips up really fast:
dup_group = self.game.platforms.copy() dup_group.remove(self) collision = pg.sprite.spritecollide(self, dup_group, True) self.game.platforms.remove(collision)So I tried in the update section where the code I first posted is, where the Platform object is created. Same thing:
while len(self.platforms) < 7: width = random.randrange(50, 100) p = Platform(self, random.randrange(0, WIDTH - width), random.randrange(-60, -40), self.kind) dup_group = self.platforms.copy() dup_group.remove(p) collision = pg.sprite.spritecollide(p, dup_group, False) self.platforms.remove(collision)Tried adding a
dup_group.empty()
just in case. Nothing.Here is the kill code for when the player falls to his death. This is when the game freezes and eventually runs out of memory:
# Die! if self.player.rect.bottom > HEIGHT: for sprite in self.all_sprites: sprite.rect.y -= max(self.player.vel.y, 10) if sprite.rect.bottom < 0: sprite.kill() if len(self.platforms) == 0: self.die_sound.play() self.playing = FalseThis is all part of a tutorial. Thought it was strange that what I want to do wasn't in the tutorial... guess I found out why.