我有一个(非常)小的Pygame演示,在Linux和OS X下表现不同 . 演示创建一个500x500窗口,然后进入一个收集事件的循环 . 使用Pygame Clock将“帧速率”调节为5 fps . 在OS X下执行时,event.get()永远不会每帧返回两个以上的排队鼠标事件 . 在Linux下执行时,event.get()返回更多事件,并能够准确跟踪帧之间的鼠标移动 .
EDIT: I have found some comments that suggest there may be issues with mouse events in SDL (which underlies Pygame) under OS X. This Pygame installation is using 1.2.14.
有谁知道我做错了什么,或者我怎么能让OS X捕获帧之间类似的丰富事件?
这是代码:
import pygame
from pygame.locals import QUIT
pygame.init()
pygame.display.init()
display = pygame.display.set_mode((500,500))
clock = pygame.time.Clock()
done = False
while not done:
clock.tick(5)
events = pygame.event.get()
if len(events) > 1:
print len(events)
for event in events:
if event.type == pygame.locals.QUIT:
done = True
示例输出如下 . 这些是在同一台(双启动)机器上捕获的 .
OS X输出(在窗口周围移动鼠标时):
$ python pygameevent.py
2
2
2
2
2
2
2
3
2
2
Linux输出(在窗口周围移动鼠标时):
$ python pygameevent.py
18
14
21
15
12
15
19
24
23
21
18
3
10