The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: calculate the mouse movement distance

  1. #1

    calculate the mouse movement distance

    I am wondering if anyone can share with a good example on how to detect the distance of the mouse movement in a certain time. Id like to be able to calculate the distance the mouse was moved from one point to another in certain time (one second) and compare these values. Please let me know if you have any good sample. Thank you in advance.

  2. #2
    As far as I know, there's no built-in API to do this. You might just have to store the mouse X/Y position at a given time, then later compare it to the current mouse position.

    If you want to figure out how much it moved as opposed to its displacement, that would be trickier. That is, in one second, the user could have moved the mouse across the entire screen then back to the starting point. If you compared to start and end points, it would say the user moved very little (or none at all). If that's an issue, then you'll probably have to add up all the distances traveled each frame instead of simply comparing the start and end points.

    Hope that helps!

  3. #3
    You are going to have to use some flash math. More specifically the Pythagorean theory to get the distance. A good tutorial dealing with proximity is http://www.gotoandlearn.com/play?id=17.

  4. #4
    Code:
    var mX:Number = _xmouse;
    var mY:Number = _ymouse;
    
    function checkDistance()
    {
    	clear();
    	//trace('new distance: ' + Math.sqrt(Math.pow((mY - _ymouse), 2) + Math.pow((mX - _xmouse), 2)));
    	lineStyle(1, 0x000000);
    	moveTo(mX, mY);
    	lineTo(_xmouse, _ymouse);
    	mX = _xmouse;
    	mY = _ymouse;
    }
    
    setInterval(checkDistance, 1000);
    sample of post 2...
    Too many letters, I cant understand you.. :vodka::bears:
    If i make grammatical mistakes plz correct me. $)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012