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


Messages In This Thread
Game boss causing huge slowdown - by michael1789 - Mar-06-2020, 03:04 AM
RE: Game boss causing huge slowdown - by metulburr - Mar-06-2020, 09:34 AM
RE: Game boss causing huge slowdown - by Windspar - Mar-07-2020, 01:33 AM
RE: Game boss causing huge slowdown - by Windspar - Mar-07-2020, 07:30 AM
RE: Game boss causing huge slowdown - by metulburr - Mar-07-2020, 11:58 AM
RE: Game boss causing huge slowdown - by Windspar - Mar-07-2020, 06:37 PM
RE: Game boss causing huge slowdown - by Windspar - Mar-07-2020, 11:51 PM
RE: Game boss causing huge slowdown - by Windspar - Mar-08-2020, 02:34 AM
RE: Game boss causing huge slowdown - by Windspar - Mar-08-2020, 08:41 AM
RE: Game boss causing huge slowdown - by metulburr - Mar-08-2020, 11:14 AM
RE: Game boss causing huge slowdown - by Windspar - Mar-08-2020, 12:14 PM
RE: Game boss causing huge slowdown - by metulburr - Mar-08-2020, 11:04 PM
RE: Game boss causing huge slowdown - by metulburr - Mar-08-2020, 11:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  (HELP GREATLY APPRECIATED) New user- Huge Pygame Installation Problem! Jbomb 1 2,866 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