Skip to main content
Inspiring
April 8, 2008
Question

Smoothing out jittery mouse input

  • April 8, 2008
  • 3 replies
  • 762 views
I'm designing a touch screen interface. One problem is that the cursor tends to jitter based on the small variations of pressure a finger puts on the screen. Is there a script to dampen or smooth small variations of the cursor position?

This topic has been closed for replies.

3 replies

Inspiring
April 10, 2008
You're welcome. It would rpobably be a good idea to square the minJitterDist and to square the deltas. I'm guessing Math.abs(dx) is more of a processor hit than dx*dx. So the conditional becomes:

if(dx*dx>minJitterDist || dy*dy>minJitterDist;

Of course if your program isn't too taxing it might not matter.

I would also maybe look at taking it out of an onEnterFrame and using a setInterval. Depending upon your FPS and all that might ease some resources and/or make it more responsive.

There are a lot of ways to go with this. Glad you are making progress.
Inspiring
April 8, 2008
Well without knowing exactly how you are reading the mouse position and what you are using it for it is hard to offer concrete advice.

You don't want to limit the sample rate (times per second) too much or users will feel that it isn't responsive.

If you've characterized the the jitteriness and it tends to be sub-pixel or so then perhaps rounding will help. But if the jitteriness is in the 5 to 8 pixel range then rounding might not be helpful at all.

I'm trying to imagine what I would do and I'm having a hard time imagining exactly what I would do. However I'm pretty sure that I would set asside my current project and try to create the simplest test case I could come up with. Run a few tests, try a few approaches, and then integrate the result with the original files.

If I felt really good about it that would be the end of it. If I felt it was a bit hacked/cobbled together I might post it in these forums and see what input others had.

Thinking about this I just thought about the visuals. The pointer is going to be at the xmouse and ymouse (caps might be wrong, I'm not good enough at AS3 yet to just know the properties off the top of my head). You can't change that. But you can hide the pointer and attach a clip of your own design. For testing purposes I would leave the pointer visible so you can visually compare the pointer to your surrogate.
Inspiring
April 8, 2008
I only have Flash 8 (so no AS3) at work to try this out. Here is what I came up with in AS2. Without seeing exactly what you are seeing it is hard to tell if this would work. It requires that you have a clip on the stage called "pointer." Try different values for the variables. Try it with the mouse hid and not hid. See what you think.
Inspiring
April 10, 2008
Wow, that works great! Thank you very much!
Inspiring
April 8, 2008
Interesting question. My guess would be that there aren't that many folks who have had to deal with this and there probably isn't a general purpose touch screen jittery cursor damping program out there.

But that being said, all you have to do is what needs to be done. First characterize the jitter, is there a way (programatically) that you can tell when it is happening? Then some kind of switch that looks for that condition and if so either averages or just stops the cursor.

Or perhaps just some kind of damping (friction) that is high when the motion is small, but low when the motion is large.
Inspiring
April 8, 2008
I notice this problem with some Wii games too. Some games have a choatic jittery cursor, while some are buttery smooth.

The simplest way I can think of would be to merely round the mouse coordinates to the nearest whole number and only sample it "x" times per second. But I'm not nearly versed in ActionScript to do this from the top of my head. I'd appreciate any pointers or code I could use.