Best way to switch to new level

This is how I do it and always did:
(Restarting the whole scene every time)

export default class MainScene extends Phaser.Scene {
  currentLevel

  constructor() {
    super({ key: 'MainScene' })
  }

  init(props) {
    const { level = 0 } = props
    this.currentLevel = level
  }

  preload() {
    // load the correct map based on this.currentLevel
  }

  create() {
    console.log(this.currentLevel)

    // start the next level after 2.5 seconds
    this.time.addEvent({
      delay: 2500,
      callback: () => this.scene.restart({ level: this.currentLevel + 1 })
    })
  }
}

Maybe my Phaser 3: Platformer Example will help you too!

4 Likes