我想知道-是将你的pygame“窗口”表面保存为一个变量,然后在变量上为每个图像调用blit,还是调用get_surface().blit(...)每次都是吗?
特别是当涉及到游戏时,有很多很多pngs/精灵/东西需要展示。我想知道有没有人在调用函数而不是在变量中保存“屏幕”的性能方面有经验?
一个带有变量的示例:
screen = pygame.display.get_surface()
while True:
screen.blit(my_image.png)示例二:
while True:
pygame.display.get_surface().blit(my_image.png)致以最好的问候,Cribber
发布于 2019-04-26 01:51:01
我已经接受了这个建议,并亲自运行了一个性能测试,显然这并不重要。
因此,决定因素是可读性,我将使用screen.blit()的变量选项。
start_time = time.time()
while i <= 1000:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#pygame.display.get_surface().blit(png, (x, y))
screen.blit(png, (x, y))
pygame.display.flip()
i += 1
elapsed_time = time.time() - start_time1) display.get_surface().blit()
Sum = 14.827981948852539
x100 - Elapsed time: 0.31400012969970703
x1000 - Elapsed time: 2.9339892864227295
x1000 - Elapsed time: 2.897007465362549
x1000 - Elapsed time: 2.9139883518218994
x1000 - Elapsed time: 2.834001064300537
x1000 - Elapsed time: 2.9349956512451172) screen.blit()
Sum = 14.843550443649292
x100 - Elapsed time: 0.2919886112213135
x1000 - Elapsed time: 2.8539986610412598
x1000 - Elapsed time: 2.914994239807129
x1000 - Elapsed time: 2.926569938659668
x1000 - Elapsed time: 2.9420039653778076
x1000 - Elapsed time: 2.9139950275421143https://stackoverflow.com/questions/55836888
复制相似问题