Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Accurate Clicks Per Second

Hi guys. It's been a while and this place has changed a bit. Well, I'm working on a clicker-style game and I need an accurate way to calculate clicks per second (cps). I've sort of hard-coded a simple way of doing it, but I find it isn't as accurate.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
///===CREATE EVENT===///
taps=0;// number of taps/clicks player makes
frames=0;// initial time keeping variable
sec=0;// conversion from frames to seconds
taps_per_sec=0;// how many taps/clicks per second

///===STEP EVENT===///
//...increase time
frames += 1;

//...convert time (frames) to sec (seconds)
sec = frames / room_speed;

//...find tps
taps_per_sec = ceil(taps / sec);

///===ALARM 0===///
// Each time the player clicks the alarm is reset to room_speed and taps is
// increased by 1
///...reset
taps=0;
frames=0;
taps_per_sec=0;


This works a okay, but I'm in need of a more accurate method. This is where algebra comes in and I stink at creating algebraic equations. Maybe if there is a time stamp of each click and then calculating the time in between clicks, like the pneumatic road tubes calculating car speed. I don't know. I'm kind of stuck here though so any help would be appreciated.
by

1 Answer

vishaljlf39
I think if you put a counter in your events loop it will do what you want:

1
2
if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
self.click_counter += 1


No one is going to click faster that 60 times per second, so it should be pretty accurate.

Login / Signup to Answer the Question.