Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
Delay in gameloop while pressing key

Trying to figure something to had a delay for my homemade animation. So i have a little function that animate a container (rotation, pivot) and i use to move it from the gameloop by pressing arrow key, the problem is the animation speed run way too fast and if i use a sort of delay function like setTimeout it's not working for the first time pressing and i can't basically put a cycle starter on top cause it's would play 2x instead of 1. Any idea ?

let step = 0, keyboard = [];

function rotate(){
 switch(step){
     case 0: 
        //first rotation
     break;
     case 1:
        //next rotation 
     break;
     //then add more rotation if you want 
  }
}

function gameLoop(){
 if(keyboard["ArrowLeft"] || keyboard["ArrowRight"])
    // here i need something like delay of 1s for each rotate();
}

window.addEventListener("keydown", event => {
  if(["ArrowLeft", "ArrowRight"].indexOf(event.key) != -1)
    keyboard[event.key] = true;
});
window.addEventListener("keyup", event => {
  if(["ArrowLeft", "ArrowRight"].indexOf(event.key) != -1)
      keyboard[event.key] = false;
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!