[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] collidepoint



On 9/3/07, Eric Hunter <hunter.eric1@xxxxxxxxx> wrote:
>         mpress = pygame.mouse.get_pressed()
>         for event in pygame.event.get():
>
One thing that is not intuitive at all to someone who doesn't have
much experience with event loop stuff is that it's common for an
application to not know about the result of the events in it's queue
until after it's processed it's event loop. It's that way with SDL.

so when you call "pygame.mouse.get_pressed()" on the line before
calling "pygame.event.get()", it's like you are calling get_pressed
before the mouse button was pressed, because the event loop hasn't got
a chance to go learn about the button press. If you change the lines
quoted above to:

    queue = pygame.event.get()
    mpress = pygame.mouse.get_pressed()
    for event in queue:

you will see your code works (cause mpress will get the button state
after the event queue got to hear about the mouse click)

...also, Mike's suggestion of using event.button and event.pos makes
the most sense given  that you are checking for the click when you are
iterating the processed events.