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

Re: [pygame] Speed of mouse position capture



Brian Bull wrote:
Dear list,

So in my Pygame app, I am trying to create a system where the user
interacts with the game by drawing glyphs on the screen with the mouse -
for example, drawing a small circle around an enemy with the mouse might
mean 'zap a Sleep spell at them'.

I am encountering one difficulty, which is that the speed of mouse
position capture seems quite slow. I had expected that the app would
receive a MOUSEMOTION event every time the mouse shifted to a new pixel,
and that connecting up the locations of these MOUSEMOTION events would
give an almost exact representation of the path of the mouth across the
screen. However, what happens in practice is that, if the mouse is
moving fast, consecutive MOUSEMOTION events can be separated by more
than 20 pixels. This makes it very hard to interpret the path of the
mouse with enough precision - it ends up divided into a small number of
long line segments.

Is there a way to make Pygame sample the position of the mouse more
often?

(I suppose one answer would be 'get a faster PC' - it is 5 years old and
running Pygame in debug mode from WING probably slows it down even more
- but if there was something I could do on the software level, it would
be better...)

TIA,
Brian

"The information contained in this transmission is confidential. It is intended for the named address only. If you are not the named address you may not copy, distribute or take any action in reliance upon this transmission"

If you're on a Windows box, try using the DirectX engine. I notice that that engine DOES capture every mouse position change, and I have to throw away all but the first on every pass through the loop, otherwise my game goes too slow. Using the WINDIB engine, it throws away positions, and I experience missing positions, as you mentioned.

For me, that's desired behavior. For you, you could try interpolating the missing values if you absolutely must have them.