An easy way to get the mouse speed

Source: Internet
Author: User
Tags pow
Mouse | Speed today a friend asked about how to calculate the speed of the mouse movement, thought for a while, there is a more convenient way to achieve, the principle is relatively easy to understand, before really did not think, feel good on the hair and everyone to share, I hope to help ...
Say the general production steps:
After creating a new file, create a dynamic text with the variable name speed;
Create a new layer and insert a key frame for writing the code;

In the first frame write:


X1=_root._xmouse
The y1=_root._ymouse//gets the coordinates of the mouse in the first frame;
In the second frame write:

X2=_root._xmouse
The y2=_root._ymouse//gets the coordinates of the mouse in the second frame;
Length=math.sqrt (Math.pow (x2-x1,2) +math.pow (y2-y1,2));
This sentence is the key, using the distance formula to find the mouse between the two frames of distance difference;
Time = 1/12*2;//to find out the need to play two frames, note that the frame frequency is 12fps;
Sudu = length/time;//using the velocity formula to find out the speed;
Sudu = Math.Round (sudu*100)/100;//will find out the speed of two decimal places
speed=x;//the speed of the equation to the dynamic text box
Finally, the test results can basically measure the speed of the mouse movement.

How do you have other good ways to achieve the speed of the mouse to obtain, you can send up and share, discuss the exchange.

Original file:

Click to browse the file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.