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

185
Views
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 answers
Answer question

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 Report
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!