Any way to speed up Python and Pygame?

前端 未结 6 1471
故里飘歌
故里飘歌 2020-12-28 08:37

I am writing a simple top down rpg in Pygame, and I have found that it is quite slow.... Although I am not expecting python or pygame to match the FPS of games made with com

6条回答
  •  天涯浪人
    2020-12-28 09:19

    First, always use 'convert()' because it disables alpha which makes bliting faster. Then only update the parts of the screen that need to be updated.

    global rects
    
    rects = []
    
    rects.append(pygame.draw.line(screen, (0, 0, 0), (20, 20), (100, 400), 1)) 
    
    pygame.display.update(rects) # pygame will only update those rects
    

    Note:

    When moving a sprite you have to include in the list the rect from their last position.

提交回复
热议问题