Timer skipping during transition

Timer skipping during transition
0.0 0

#1

Have been building a javascript powered pairs game in spare time at work but now I’m having an issue where the timer seems to pause for a second while the card flip is transitioning, this leaves the final times a bit off. I’ve tried removing the setTimeout from the checkClass and hasWon functions, but it didn’t seem to help.

Added it to a JSfiddle here, padon the appearance but i couldn’t be bother to set up image hosting when it’s not really needed for this issue.
https://jsfiddle.net/gwesolo/de5z9mkd/
The timer will start once the first tile is clicked, the reset button works to reset the whole game and the submit/leaderboard is just for show.

Any insight on what’s happening here would be awesome! :slightly_smiling_face:


#2

I think I get what is happening. You are removing and re-adding the setInterval every time you flip a card. So a method is called every second (if you don’t flip a card). But what happens if you flip a card when half a second has passed after the last call to that method? It will reset the interval and wait a second, but it should have waited half a second. So the time you measured is “delayed” by on average half a second (each time it is delayed by a value ranging between 0 and 1 second).


#3

Cheers, that was helpful!

Ended up creating a new function for starting the timer that checks if the timer is already running and if not, starts it up. No more clearInterval on a card click.

All worked fine after that