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

Re: [pygame] Event polling, is there a standard trick to combine ...



Ta
I'll try get_rel, should work, will it strip all the queued mouse events for
me though ?

Pete Shinners wrote:

> > x = reduce(lambda x,y: x+y, map(lambda x: x.rel[0],motions))
> > y = reduce(lambda x,y: x+y, map(lambda x: x.rel[1],motions))
> >
> > This should give you the amount of totally moved pixels in (x,y).
> >
> > Of course there's got to be some better code for that.. I just made that
> > one up fast.. and I also don't believe it's worth it anyways.. as it'll
> > be certainly faster to save the old mouse position and when you check it
> > again just use pygame.mouse.get_pos() and calculate the difference by
> > a simple subtraction.. much easier, cleaner and faster.
>
> yes, this should work fine. although like frank mentioned, if you
> just want to get the current mouse position, instead of parsing
> through all the mousemotion events, just get the current position
> from the pygame.mouse module.
>
> also, if you are looking for relative positions, there is an
> easier way then mentioned above. just make use of the
> pygame.mouse.get_rel() function, which will give you the
> amount of mouse motion since the previous time you called the
> function.
>
> one slightly unrelated thing, but just so you know. if you
> hide the cursor "pygame.mouse.set_visible(0)", and grab the
> machines input "pygame.event.set_grab(1)", internally pygame
> will use an unlimited mousing area. so you can scroll infinitely
> in any direction and not worry about the mouse getting stuck on
> the edges of the screen :]
>
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org