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

291
Vistas
Is setInterval cleared on scene change Phaser 3?

Are all setIntervals cleared on scene change in Phaser 3? For example, if I have this code:

class ExampleScene extends Phaser.Scene {
  constructor () {
    super();
  }
  preload () {

  }
  create () {
    setInterval(() => console.log(true), 1000);
  }
  update () {
  
  }
} 

and I change scenes, will it continue to log true to the console? Is there an alternative in Phaser that doesn't require that I remove all intervals manually?

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

0

The short answer is, No. Since setInterval is a javascript function.
For details on the function: here in the documentation on mdn

What you can do is "save" the setInvertal calls/id's in a list and clear them on a specific scene event like, shutdown, pause, destroy ... . When that event fires you can then stop all saved intervals, or so (details to possible Scene events).
This is also considered good practice, since you always should cleanup resources, when leaving a phaser scene.

Example (here with the shutdown event):

 ...
 // setup list for the intervals, that should be cleared later
 constructor () {
    super();
    this.intervals = [];
  }

 create () {
     ...
     // example of adding an interval, so that I can be cleanup later
     this.intervals.push(setInterval(() => console.log(true), 1000));
     ...

     // example listening to the shutdown Event
     this.events.on('shutdown', this.stopAllIntervals, this);
 }
 ...
 // example "cleanup"-function, that is execute on the 'shutdown' Event
 stopAllIntervals(){
     for(let interval of this.intervals){
          clearInterval(interval);
     }
 }
 ...

And now you just hat to call the stopAllIntervalsin the desired event function, when you want to stop them all.

From the offical documenation, on the shutdown Event: ... You should free-up any resources that may be in use by your Scene in this event handler, on the understanding that the Scene may, at any time, become active again. A shutdown Scene is not 'destroyed', it's simply not currently active. Use the DESTROY event to completely clear resources. ...

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