Jump to content

Restart Scene: Collider Destroy


digitsensitive
 Share

Recommended Posts

Hello!

I was wondering if this is the correct approach, regarding management of the collider when restarting a scene.
 

I have added this collider in my scene:

this.physics.add.collider(
  this.traps,
  this.player,
  this.playerTrap,
  null,
  this
);

I restart the scene as soon as this collision happens in the playerTrap() function:

  private playerTrap(): void {
    this.player.setAlive(false);
    this.cleanScene();
    this.scene.start("GameScene");
  }

The cleanScene():

private cleanScene(): void {
 this.physics.destroy();
}

Without the cleanScene() function he restarts the scene infinitely. I always thought that when using this.scene.start he auto cleans everything and reboots.

Link to comment
Share on other sites

  • 1 month later...

Thanks so much! I was using a version from an online tutorial and didn't check to make sure it was the latest. Do you know what was happening before? I suspected the current physics object and sprites weren't being removed immediately when the scene was restarted, so it kept calling the collision method. I'm a beginner, though, so that's probably not too accurate

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...