【问题标题】:Pygame : The game stops temporarily when I am moving the windowPygame:当我移动窗口时游戏会暂时停止
【发布时间】:2020-05-13 09:29:32
【问题描述】:

我是 PyGame 的新手,我正在制作游戏。直到我发现,例如,当您将窗口移动到桌面的另一个位置时,游戏会暂时停止。但是当我使用 pygame.time.get_ticks() 时,游戏的滴答声仍在运行。

所以我制作了一个只包含必要代码的全新程序,它做同样的事情。

有人能解释一下为什么会这样吗?我们是否可以解决这个问题?

import pygame

screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('The Test Program')

running = True
update_counter = 1

while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False

  pygame.display.flip()
  print(str(update_counter) + " updates")
  update_counter += 1


pygame.quit()
quit()
# So try to move the window across your screen and you will see that, prints will stop and they will resume when you will release the click

【问题讨论】:

  • 当我在 Linux Mint(使用 PyGame 1.9.6)上运行时,它会一直打印 - 所以它可能取决于您使用的系统。当您移动窗口时,可能某些系统会停止运行代码 - 这可能是您系统中的正常现象。
  • 虽然也没有明确的答案,但这是同一个问题:stackoverflow.com/questions/10122289/…

标签: python pygame drag-and-drop window code-freeze


【解决方案1】:

所以有人告诉我这很正常,所以我认为这只是在 Windows 上,但没有解决方案。当光标离开窗口以使其正常时,我放置了一个在屏幕上显示暂停符号的脚本。

【讨论】:

    猜你喜欢
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多