Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node + Phaser.HEADLESS --> (Phaser.Scene).add function does not add new scene #5872

Closed
micsun-al opened this issue Oct 14, 2021 · 3 comments
Closed

Comments

@micsun-al
Copy link

micsun-al commented Oct 14, 2021

Version

  • Phaser Version: Phaser v3.55.2-FB (Headless | No Audio)
  • Operating system: Windows 10
  • Browser: $ node v14.17.6

Description

Using node + Phaser.HEADLESS, (Phaser.Scene).add function does not add new scene. The associated constructor, init, preload, create, and update functions also do not run. Changing the Phaser.Game type to Phaser.CANVAS makes the associated functions run correctly.

Example Test Code

class MainScene extends Phaser.Scene {
  constructor(config) {
    super(config)
  }
  
  create() {
    const dynamicSceneName = `dynamicSceneName${Phaser.Math.Between(0, 9999999)}`
    console.log(`Adding ${dynamicSceneName}...`)
    this.scene.add(dynamicSceneName, SomeDynamicScene, true)
  }
}

class SomeDynamicScene extends Phaser.Scene {
  constructor(config) {
    super(config)
    console.log(`config:`, config)  // THIS DOES NOT GET CALLED ON (NODE + `Phaser.HEADLESS`), BUT WORKS ON (NODE + `Phaser.CANVAS`)
  }
  
  create() {
    console.log(`SomeDynamicScene: create`) // THIS DOES NOT GET CALLED ON (NODE + `Phaser.HEADLESS`), BUT WORKS ON (NODE + `Phaser.CANVAS`)
  }
  
  update(time, deltaTime) {
    console.log(`SomeDynamicScene: update`) // THIS DOES NOT GET CALLED ON (NODE + `Phaser.HEADLESS`), BUT WORKS ON (NODE + `Phaser.CANVAS`)
  }
}

var config = {
    type: Phaser.HEADLESS,   // THIS DOES NOT WORK ON NODE (WORKS IN BROWSERS)
    // type: Phaser.CANVAS,  // THIS WORKS ON NODE
    scene: [
      MainScene
    ]
}

var game = new Phaser.Game(config)

Additional Information

phaser: 3.55.2
webpack 4.29.0
ts-node 9.1.1
ts-loader: 5.3.3
node: 14.16.0

@micsun-al micsun-al changed the title Phaser.HEADLESS does not run create, update, etc methods on dynamically added Phaser.Scene node + Phaser.HEADLESS --> (Phaser.Scene).add function does not add new scene Oct 14, 2021
@samme
Copy link
Contributor

samme commented Oct 14, 2021

Check if MainScene#update() gets called.

@micsun-al
Copy link
Author

micsun-al commented Oct 14, 2021

MainScene#create() and MainScene#update() gets called correctly (with either Phaser.HEADLESS or Phaser.CANVAS on node).

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants