[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Joystick missing events?
Hello Pygamers,
I've got some weird behavior regarding joystick control that may be a
FAQ. If so, please point me to the right URL.
It seems that if I use pygame.event.get() to read joystick events, I end
up missing some during rapid joystick axes changes.
Full code for this is here:
http://taskboy.com/programs/Main3.py
The relevant snippet is:
for e in pygame.event.get() :
if e.type == pygame.JOYAXISMOTION :
currDir = change_direction(e.axis, e.value)
I've got a USB PS-style controller (Logitech Precision).
The behavior can be seen by rapidly changing directions a few times
and perhaps end up going in a NW, SE, NE, or SW direction. If you
experiment with the full code, you'll notice that the dot you control
seems to get ignore your direction change.
I can rewrite this bit (admitting a little race condition) to use
polling:
v1 = J.get_axis(0)
v2 = J.get_axis(1)
if v1 > 0.5 or v1 < -0.5 :
currDir = change_direction(0, v1)
else :
currDir = change_direction(1, v2)
J is an initial Joystick object. Full code here:
http://taskboy.com/programs/Main4.py
The performace is better when using events. The polling prevents the
above problem, but I'd prefer to use the event queue.
Is this a known problem? Have I written the even logic poorly?
Thanks for your help,
--Joe