使用pygame.event.wait()减少事件之间的系统开销。但我使用它的方式似乎过滤掉了大多数事件。不能将它放在我的程序中的正确位置。
有人可以看看并评论我是否使用它错了吗?
LEFT = 1
而True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print "You pressed the left mouse button at (%d, %d)" % event.pos
elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print "You released the left mouse button at (%d, %d)" % event.pos
pygame.display.update()
pygame.event.wait()
答案 0 :(得分:0)
pygame.event.wait
返回有问题的事件并从队列中弹出,因此您必须使用其他事件进行管理:
for event in [pygame.event.wait()]+pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print "You pressed the left mouse button at (%d, %d)" % event.pos
elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print "You released the left mouse button at (%d, %d)" % event.pos