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

249
Vistas
How to run a JS delayed repeated function in update( ) with a conditional?

I'm developing a prototype game using framework Phaser with JavaScript. So, I'm trying to run a delayed function with a conditional var isPlaying == true in update() method, but it's not working. The function works, but not with the defined delayed time. It runs quickly and probably at FPS (deltaTime).

update(){

   if(isPlaying){

     this.time.addEvent({delay: 2500, callback: createItem, callbackScope: this, loop: true}); 

   }

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The update function is fired at FPS, so you're adding a new event each frame. Each event that you add is with loop: true so it will call the callback function every 2500.

Depending on what you want to achieve, you may want to put the addEvent at the end of the create function instead of update and then unpause it only once in update.

var timer;

create() {
     timer = this.time.addEvent({delay: 2500, callback: createItem, callbackScope: this, loop: true, paused: true}); 
}

update(){

    if(isPlaying && timer.paused){
        timer.paused = false;
    }

}

You can find other note about Timers here

about 4 years ago · Juan Pablo Isaza 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