首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >get_surface().blit() vs var_screen.blit()

get_surface().blit() vs var_screen.blit()
EN

Stack Overflow用户
提问于 2019-04-25 03:00:20
回答 1查看 42关注 0票数 0

我想知道-是将你的pygame“窗口”表面保存为一个变量,然后在变量上为每个图像调用blit,还是调用get_surface().blit(...)每次都是吗?

特别是当涉及到游戏时,有很多很多pngs/精灵/东西需要展示。我想知道有没有人在调用函数而不是在变量中保存“屏幕”的性能方面有经验?

一个带有变量的示例:

代码语言:javascript
复制
screen =  pygame.display.get_surface()
while True: 
    screen.blit(my_image.png)

示例二:

代码语言:javascript
复制
while True:
     pygame.display.get_surface().blit(my_image.png)

致以最好的问候,Cribber

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-26 01:51:01

我已经接受了这个建议,并亲自运行了一个性能测试,显然这并不重要。

因此,决定因素是可读性,我将使用screen.blit()的变量选项。

代码语言:javascript
复制
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()

Sum = 14.827981948852539

代码语言:javascript
复制
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()

Sum = 14.843550443649292

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55836888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档