Last active
December 21, 2015 04:29
-
-
Save quakeboy/6249816 to your computer and use it in GitHub Desktop.
Calculating clicks per minute based on mouse clicks. Needed to calculate something for my game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (e.type == MouseEvent.MOUSE_DOWN) | |
{ | |
if (last_dt == 0) //first time. no avg yet. | |
{ | |
last_dt = getTimer(); | |
} | |
else | |
{ | |
if (new_dt == 0) //second time, first cps, first average | |
{ | |
data_count++; | |
new_dt = getTimer(); | |
average_dt = 60000 / (new_dt - last_dt); | |
sum += average_dt; | |
} | |
else | |
{ | |
data_count++; | |
new_dt = getTimer(); | |
//latest clicks per sec calculation | |
cps = 60000 / (new_dt - last_dt); | |
//new average | |
average_dt = (average_dt * (data_count-1)/data_count) + (cps/data_count); | |
} | |
debug_tf.text = Math.round(average_dt) + ""; | |
last_dt = new_dt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
******* var declarations ******
private var debug_tf:TextField = new TextField();
private var last_dt:Number = 0, new_dt:Number = 0, cps:Number = 0;
private var average_dt:Number = 0, data_count:Number = 0, sum:Number = 0;