【发布时间】:2018-01-06 13:13:18
【问题描述】:
我目前正在尝试使用 pygame 开发电脑游戏 - 我想显示游戏的背景图像(2D 跳跃并运行)。
但是,当显示全屏背景图像时,我注意到帧速率显着下降,超过一定的窗口大小:
Windowsize | Time to blit the image | (~ FPS)
1280x720: 0.029s (~32 FPS)
1366x768: 0.031s (~29 FPS)
1600x900: 0.042s (~22 FPS)
1920x1080: 0.062s (~15 FPS)
是否有其他更有效的方式来对图像进行位图处理?我不想将游戏限制在 1366x768 或更低的小窗口大小......
我尝试使用 KB 大小较小的图像,并尝试使用 1/4 大小的 4 张图像来覆盖屏幕,但时间保持不变。
游戏在 pygame 屏幕上运行,所以我不能使用任何功能,例如Tkinter(因为他们需要一个 Tkinter 表面)。
目前我正在使用pygame的以下功能:
# Once at the beginning
screen = pygame.display.set_mode((screenWidth_X, screenHeight_Y))
# Every frame
screen.blit(background_Image, (0,0))
任何帮助/建议将不胜感激!
【问题讨论】:
-
加载图片后,是否调用了convert方法(
background_Image = background_Image.convert())?那应该有所作为。 Here's the documentation -
不,但我明天会试试看!感谢您的提示!
-
Blitting 未转换的表面确实会影响性能。始终使用
convert或convert_alpha方法。