我正在使用一个函数来等待控制器出现,但我遇到了一个问题。我想在我按下一个键时停止这个功能。通常这些事件处理得很好,但在这一部分工作得很糟糕。事件似乎很晚才添加到事件队列中,有时甚至根本没有。我的猜测是因为pygame.joystick
的未初始化和重新初始化。我只是不知道怎么解决它。我用这个程序来创建错误:
import pygame, sys
from pygame.locals import *
pygame.init()
SCREEN = pygame.display.set_mode((500,500))
ChangeRun = False
pygame.joystick.init()
if pygame.joystick.get_count() == 0:
while pygame.joystick.get_count() == 0:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type in [KEYUP, KEYDOWN]:
if event.key == K_ESCAPE:
ChangeRun = True
if ChangeRun == True:
break
pygame.joystick.quit()
pygame.joystick.init()
pygame.quit()
sys.exit()
我想用escape键结束程序,但只有在多次按下后才有效。QUIT
事件也会发生同样的情况。当打印事件时,我发现大部分时间没有找到事件。
我使用windows8.1和python3.4和pygame1.9.2
我没有操纵杆,所以我不能测试它,但通常我会做类似于鼠标的操作,我不会等待控制器:
相关问题 更多 >
编程相关推荐