digitsensitive

Restart Scene: Collider Destroy

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.