All basic Pygame examples I've seen just redraw the background over everything and then the sprites over that. This should cause performance issues later on (because you're adding at least 2 new images to the window for every frame rate tick without ever removing them). Is there a better way?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If updating the entire screen is fast enough, this is already the "best" way, since it's the simplest.
If drawing to the screen is a performance bottleneck, then it can be better to just update only the parts of the screen that are changed. You probably want to use pygame's DirtySprite
and LayeredDirty
classes. LayeredDirty's draw
function returns a list of Rect
instances that describe the parts of the screen that needs updating, and you can just pass this list to pygame.display.update
.