pygame - 全屏可调整大小的窗口会导致延迟

时间:2021-03-23 19:00:20

标签: python pygame pygame-surface

我正在制作一个简单的平台游戏。为了让它顺利运行,它需要以大约 <110 fps 的速度运行。当游戏的分辨率为 640 x 512 时,它会在那里运行,但是当我将其放大到 1280 x 1024 时,它的帧速率会减半 我该如何解决这个问题?为什么会发生这种情况?

注意:这不是我的完整代码,而是发生 blitting/resize 的代码片段。

resized = True
screen = display.set_mode((640, 512), RESIZABLE)
blitSurface = Surface((1280, 1024)).convert()

while: true:
  for events in event.get():
    if events.type == VIDEORESIZE: resized = True

  blitSuface.blit(bg[0][0], bg[0][1])
  blitSuface.blit(bg[1][0], bg[1][1])
  blitSuface.blit(bg[2][0], bg[2][1])

 if resized:
    fit_to_rect = blitSuface.get_rect().fit(screen.get_rect())
    fit_to_rect.center = screen.get_rect().center
 scaled = transform.smoothscale(blitSuface, fit_to_rect.size)

 resized = False

0 个答案:

没有答案