Python Forum
[PyGame] Game boss causing huge slowdown
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Game boss causing huge slowdown
#21
Its a recursive function that is bottlenecking your code. You are creating objects that create more objects themselves.

So i understand the concept of Boss2 class adding Boss_body_seg objects to add to increase its length, but i dont understand why you are creating objects and not storing them in Boss_body_seg of itself? So if i comment out this is stops dragging.

class Boss_body_seg(pg.sprite.Sprite):
        
    def __init__(self, prev_seg, game, num):
        
        self.groups = game.boss_group
        self._layer = prev_seg._layer - 1
        pg.sprite.Sprite.__init__(self, self.groups)
        self.game = game
        self.prev_seg = prev_seg

        
        
        self.image = self.game.boss2_body
        self.rect = self.image.get_rect()
        
        self.integretty = 200
        self.pos = self.prev_seg.prev_pos
        self.num = num - 1
        self.direction = self.prev_seg.direction
        self.last_update = pg.time.get_ticks()
        self.frame_rate = 120
        self.frame = 0
        
    def update(self, game, dt):
        #if self.frame == 10 and self.num > 0:
        #        Boss_body_seg(self, self.game, self.num)
        now = pg.time.get_ticks()
...
Recommended Tutorials:
Reply
#22
(Mar-08-2020, 11:44 PM)metulburr Wrote: not storing them in Boss_body_seg of itself?

I thought the recursion would only make the spawning slower, not that it would impact anything once it was done doing it's thing. It was also my means of spacing the segments out. I don't know how I'm going to do that now.

If I create all the segments from the __init__ of the boss's head and pass each the previous segment from there, I won't face the same slowdown?

such as:
seg1 = Boss_body_seg(boss_head, self.game)
seg2 = Boss_body_seg(seg1, self.game)
seg3 = Boss_body_seg(seg2, self.game)

etc...
no harm in trying.

Thanks

EDIT: Well, I do know hwo I'm going to space then segments... I'm going to figure out the example that Winspar posted for me! lol. It's over my head currently, but I'll get it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  (HELP GREATLY APPRECIATED) New user- Huge Pygame Installation Problem! Jbomb 1 2,782 Jan-12-2021, 07:32 PM
Last Post: MK_CodingSpace

Forum Jump:

User Panel Messages

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