我想知道-将pygame的“窗口”表面另存为变量,然后为每个图像对变量调用blit还是每次都调用get_surface()。blit(...),是否更具性能?
尤其是在游戏方面,要显示很多PNG /图片/东西。我想知道是否有人在调用函数上有过经验,而不是将“屏幕”保存在变量中?
带有变量的示例一:
<List
{...props}
filters={<OrganizationFilter />}
sort={{ field: 'name', order: 'ASC' }}
perPage={25}
>
<Responsive
xsmall={<MobileGrid />}
medium={
<Datagrid expand={<OrganizationShow />}>
<OrganizationLinkField />
<ReferenceManyField label="Users" reference="users" target="uuid_organization" sort={{ field: 'email', order: 'ASC' }}>
// PRINT: 102 users
</ReferenceManyField>
<EditButton />
</Datagrid>
}
/>
</List>
示例二:
screen = pygame.display.get_surface()
while True:
screen.blit(my_image.png)
最好的问候, 婴儿床
答案 0 :(得分:0)
我接受了建议并亲自进行了性能测试,从性能角度来看,这实际上并不重要。
因此,决定性因素是可读性,我将把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_time
1)display.get_surface()。blit()
总和= 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.934995651245117
2)screen.blit()
总和= 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.9139950275421143