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

117
Visualizações
Does javascript switchs runs continuously

i was wondering if switches runs continuously or does not need of setIntervals to run (forever). i'm making a game where in a level value changes and the switch will change all entities position based on the level;

let LEVEL = 0;

switch (LEVEL) {
    case 1: 
    player.x = 64;
    player.y = 64;
    enemy.x = 32;
    enemy.y = 32;
    break;
    case 2: 
    player.x = 0;
    player.y = 64;
    enemy.x = 72;
    enemy.y = 56;
    break;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

No. A switch is like every other statement in JavaScript: It only runs when it's reached in the step-by-step execution of the code. Your example would run exactly once, for instance. To run more often would require that you put it in a loop (but then nothing else can run except that loop) or, as you said, call a function that contains the switch from a timer.

i'm making a game where in a level value changes and the switch will change all entities position based on the level

Put the switch in a function that you call when you change the level.

over 4 years ago · Santiago Trujillo Relatório
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