[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] Blocking events problem?


I stumbled on a small problem with blocking and allowing events. We
normally don't need MOUSEMOTION events, but for a special state in the
game we want them (track movement in a popup menu), so I query the current
state to see if it wants them or not. By default they are blocked, and
having them blocked has worked ok for a some time now. As soon as I added
the extra lines in the "if" below things started to get weird. No
USEREVENTS are received anymore by the main event loop (although they are
sure pygame.event.post():ed ok), but other events work ok. Simplified the
event loop looks like this:

# by default block all motion events
pygame.event.set_blocked ( MOUSEMOTION )

# main event loop (more complex than this in reality)
while eventloop:
   # change the game into a new state
   currentState = ...

   # does the new state need mouse tracking?
   if currentState.wantMouseMotion ():
       # ok, so allow them
       pygame.event.set_allowed ( MOUSEMOTION )
       # no motion events, disallow them
       pygame.event.set_blocked ( MOUSEMOTION )

If I comment out the "if-else" thing all works just fine, but as soon as I
enable it things fail. Most events don't need motion events, so already
blocked events (by default) get blocked once more. Is it a problem to call
the same set_blocked() twice? I'll do some testing and see...

Yep, apparently adding a dummy

	pygame.event.set_blocked ( MOUSEMOTION ) 

somewhere inside the main loop seems to disable USEREVENT:s from being
received by pygame.event.poll (). Is this some known issue or have I done
something wrong?

Also, music seems to sometimes not stop when the game terminates. The
game just says it got terminated ok, but still plays music. I think
I should do an explicit stop() on the music before exiting.

      Real children don't go hoppity-skip unless they are on drugs.
           -- Susan Sto Helit, in Hogfather (Terry Pratchett)

pygame mailing list