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

182
Views
¿Cómo puedo hacer que el juego se detenga por un momento cada vez que alguien anota, en lugar de volver rápidamente al juego?

Estoy construyendo un juego para practicar mis habilidades. Cada vez que alguien anota un punto, el juego comienza de nuevo muy rápido y me gustaría que le diera un poco de tiempo antes de volver atrás. La función principal se ve así:

 function drawGame() { background(); //does the background drawChar(); drawEnemy(); drawBall(); changeMovement(); playerControls(); enemyFollowsBall(); enemyChangePosition(); checkBallCollision(); drawScore(); //if(pointScored()) { //setInterval(drawGame, 1000); //} setTimeout(drawGame, 1); }

La función sigue siendo llamada a través de setTimeOut, que gestiona las animaciones del juego. Traté de resolver mi problema con el código comentado (configuré pointScore(), que incrementa el puntaje y hace algunos reinicios, para volver verdadero), pero no funcionó como esperaba. ¿Cómo puedo obtener el efecto esperado?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Seguirías llamando a setTimeout(drawGame, 1); cuando no lo mueve a la declaración else o agrega un retorno después.

 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!