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

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



On Sun, Sep 09, 2001 at 07:18:11PM +0100, Peter Goode wrote:
> Anyone written anything which combines (e.g.) MOUSEMOTION events from
> the queue...
> So if there are several you can grab them all as one and deal with
> that...
> Might help with scrolling catchup...
You mean like adding up the relative movements? I don't think there's
something like that in the PCR and haven't seen it elsewhere.. but it
shouldn't be hard to write that yourself.
Untested code to sum up relative mouse movements:

motions = pygame.event.get([MOUSEMOTION])

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.

-- 
Raiser, Frank aka CrashChaos
IRC: 141.30.225.9:6667 #United-Programmers

"Sire, The citizens are revolting!", 
"I know... that's why I live in this castle..."
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org