Replying to my own issue. I think I have figured it out. The joystick
objects going out of scope seems to be the issue. I didn't have this
issue w/ 1.x but I can see how this is now the right way. I'm tucking
away the joysticks in an array, and I am now getting events.
Is this the "right way" to do things? The test program just init's the
joystick for every game loop which seems odd to me. Is tucking them
away after init'ing correct?
~brian
On 2/22/2021 12:29 AM, Brian Sturk wrote:
I upgraded to 2.0 recently and my joystick code no longer gets events with code
that worked w/ 1.x. All
other events are coming through OK (mouse, keyboard, window, etc).
I've spent the evening attempting to debug the issue and have come up empty.
Tried 2 different
machines and many different joysticks, all the same behavior. My joystick code
does work as far
iterating and printing out the name, etc.
The 2.0 joystick test code on the pygame site does work as I see button down
and up messages
coming through.
Is there anything in moving to 2.0 I could be missing?
Here is my joystick init code, load_joysticks is called on startup, after
setting up the screen:
def load_joysticks():
global _joystick_present
global _joystick_info
pygame.joystick.init()
msg = ''
count = pygame.joystick.get_count()
if count == 0:
_joystick_present = False
msg = 'WARNING: No joystick(s) found'
_joystick_info = msg
else:
msg = str( count ) + ' joystick(s)'
_joystick_info = msg
_joystick_present = True
for i in range( count ):
joystick = pygame.joystick.Joystick( i )
joystick.init()
name = joystick.get_name().rstrip()
msg = ':' + name + ' - ' + str( joystick.get_numbuttons() ) + '
button(s)'
_joystick_info += msg
My event queue code:
e = None
try:
if _poll:
e = pygame.event.poll() ## grab event now
else:
e = pygame.event.wait() ## wait for a GUI
event rather than chewing the CPU
... <snip> ...
elif e.type is JOYBUTTONUP or e.type is JOYHATMOTION or e.type
is JOYAXISMOTION:
print 'main(): !!joystick event!!' ## <---- I do not see
this print at all when using a joystick w/ 2.0
ret = handle_joystick( e )
I've also tried looping using
for event in pygame.event.get():
e = event
as in the example, still no events.
Any ideas greatly appreciated.
thanks,
~brian
--
.-------------------------------------------------------.
| Brian Sturk ------- http://www.briansturk.com ------ | .> )\,^a__
|-------------------------. _______ Ethical Hacker ___ |( _ _)/ /-."~
| --- C/C++/Python/ASM `----------------------------| `( )_ )/
| Linux/BSD/OSX/Windows embedded/system programming --- |_<_s_<_s
`-------------------------------------------------------'