Question

Maybe someone can help me here.

My game where you can see the issue:

http://www.acsu.buffalo.edu/~jamesber/GameOne.html#

I made a puzzle game, and included a restart game href link. It works how I want except if you press it multiple times in a row very fast, it can scramble the timer and refreshes the puzzle super fast. What I want is to put like a timer on the button where it can't be pressed for like 2 seconds once it has been pressed. I tried this:

    var new; //global variable.

    document.getElementById("restart").onclick=function(){ 
new = setTimeout(function() {
restartGame();
}, 2000);
clearTimeout(new); clearTimeout(timer); restartGame(); };

    <b><a href="#" id="restart" style="position: absolute; left: 950px; top: 65px;">New Puzzle</a><b>
Was it helpful?

Solution

How about using display:none for 2 seconds like this:

document.getElementById("restart").onclick=function(){
document.getElementById("restart").style.display = 'none';
new = setTimeout(function() {
restartGame();
}, 2000);
clearTimeout(new); clearTimeout(timer); restartGame(); };

Then when restartGame() is called after the 2 second setTimeout delay, make it reappear using document.getElementById("restart").style.display = 'inline';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top