Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda