Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
How can I make the game stops for a while everytime someone scores, instead of rhush back to the game?

I'm building a game to practice my skills. Everytime someone scores a point, the game starts again really fast and I'd like it to give it a little time before going back. The main function looks like this:

function drawGame() {

    background(); //does the background
    
    drawChar();

    drawEnemy();

    drawBall();

    changeMovement();

    playerControls();

    enemyFollowsBall();

    enemyChangePosition();

    checkBallCollision();

    drawScore();

    //if(pointScored()) {
       //setInterval(drawGame, 1000);
//}

    setTimeout(drawGame, 1);
}

The function keeps being called through setTimeOut, which manages the game animations. I tried to solve my problem with the commented out code (I set pointScore(), which increments the score and does some resetting, to return true), but it didn't work as I expected. How can I obtain the expected effect?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You would still call setTimeout(drawGame, 1); when you dont move it into the else statement or add a return after.

function drawGame() {

  background(); //does the background

  drawChar();

  drawEnemy();

  drawBall();

  changeMovement();

  playerControls();

  enemyFollowsBall();

  enemyChangePosition();

  checkBallCollision();

  drawScore();

  if (pointScored()) {
    setInterval(drawGame, 5000);
    return; // either this
  } else { // or adding the else here
    setTimeout(drawGame, 1);
  }

}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda