Feb-17-2020, 12:30 AM
This is my first attempt at the update for a sprite:
I'll add acceleration later, but the problem is with performance.
The game is one of blocks in a grid that the player mines around in. I want these particular blocks to fall if they are undermined, but having each of this kind of block try to move and perform this check each frame drags the program to a crawl.
I need to find a better way to have blocks fall if there is nothing underneath them. I'm going to work now on only doing this check when the player destroys a block, as that is the only time it would change, but I want to have a LOT of blocks in this game, so any ideas on speeding this up will help a lot.
I'm not invested in this method at all, so radical options are welcome. tnx
1 2 3 4 5 6 7 8 9 10 |
def update( self , event, dt): self .rect.y + = 5 temp_group = self .game.all_sprites.copy() temp_group.remove( self ) block_hit_list = pg.sprite.spritecollide( self , temp_group, False ) for block in block_hit_list: self .rect.bottom = block.rect.top temp_group.empty() |
The game is one of blocks in a grid that the player mines around in. I want these particular blocks to fall if they are undermined, but having each of this kind of block try to move and perform this check each frame drags the program to a crawl.
I need to find a better way to have blocks fall if there is nothing underneath them. I'm going to work now on only doing this check when the player destroys a block, as that is the only time it would change, but I want to have a LOT of blocks in this game, so any ideas on speeding this up will help a lot.
I'm not invested in this method at all, so radical options are welcome. tnx