本文介绍了当您移动/拖动窗口时,为什么 pygame 会在 pygame.event.get() 处冻结?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个循环(tick、set_caption、screen_fill、event.get()、send_frame_event、flip、repeat)

Basically I have a loop (tick, set_caption, screen_fill, event.get(), send_frame_event, flip, repeat)

当我在 Windows 7 上拖动窗口时,循环停止循环,我最终卡在 pygame.event.get() 中,我试图仅为 get 定义某些事件,例如get([pygame.QUIT]) 无济于事.

When I drag the window around on windows 7, the loop stops looping, I ended up stuck in pygame.event.get(), I have tried to define certain events only for get e.g. get([pygame.QUIT]) to no avail.

在拖动/移动窗口时,只需调用 pygame.event.clear() 具有相同的冻结效果.

Simply calling pygame.event.clear() has the same freeze effect when dragging/moving the window.

有解决方法吗?

不是完整的代码,但应该足够了:

Not full code, but should be enough:

def start(self):
    self.running = True
    Clock = pygame.time.Clock()
    while self.running:
        self.p += 25
        tickFPS = Clock.tick(self.fps)
        pygame.display.set_caption("Press Esc to quit. FPS: %.2f" % (Clock.get_fps()))
        self.screen.fill([self.p&0xFF,(255-self.p)&0xFF,255])
        self.handleEvents()
        self.raiseEvent("updateFrame")
        pygame.display.flip()
def handleEvents(self):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            self.running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self.running = False

完整代码:http://pastie.org/private/wm5vqq3f7xe0xlffy1fq

推荐答案

尝试在主循环(或 handleEvents 函数)中调用 pygame.event.pump()

Try placing a call to pygame.event.pump() inside your mainloop (or handleEvents function)

这篇关于当您移动/拖动窗口时,为什么 pygame 会在 pygame.event.get() 处冻结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:50