Learn Create Your Own Split Screen

Next Page

Now it becomes a simple matter to fix the second glitch.

We'll only obey the keystroke if the difference between the time now, and the time when the game was last running, exceeds one thousand milliseconds (one second).

function Got_Player_Input(MyEvent) { switch (game_mode) { case 'prestart': { game_mode = 'running'; break; } case 'running': { bird.velocity_y = jump_amount; break; } case 'over': if (new Date() - time_game_last_running > 1000) { reset_game(); game_mode = 'running'; break; } } // switch MyEvent.preventDefault(); }