Python Forum
[PyGame] Spawning platforms that don't touch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Spawning platforms that don't touch
#3
I ran into some problems. If I leave the "kill" part of the collision at 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 = False
This 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.
Reply


Messages In This Thread
RE: Spawning platforms that don't touch - by michael1789 - Jan-22-2020, 02:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Timing the spawning enemies MichaelEssey 2 4,762 Aug-22-2020, 05:51 AM
Last Post: SheeppOSU
  spawning enemies in pygame Elberg 2 5,735 Mar-05-2020, 09:45 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020