Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda