rblopes / generator-phaser-plus

[🛑 DISCONTINUED] It has been a long journey but development of `generator-phaser-plus` is now over. I recommend you have a look and fork `yandeu/phaser-project-template` instead.
https://github.com/yandeu/phaser-project-template
MIT License
144 stars 14 forks source link

[Bug] Uncaught TypeError: Cannot read property 'sys' of null #28

Closed raphaklaus closed 6 years ago

raphaklaus commented 6 years ago
*   Which Node.js version: 9.6.1

*   Which package manager (npm or Yarn): Yarn: 1.5.1

*   The project configuration created by Yeoman (the `.yo-rc.json` file).
{
  "generator-phaser-plus": {
    "meta": {
      "createdWith": "3.0.0-beta.2",
      "creationDate": "2018-04-21T22:02:00.600Z"
    },
    "objects": {
      "dest": "app/scripts/objects/"
    },
    "plugins": {
      "dest": "app/scripts/plugins/"
    },
    "scenes": {
      "dest": "app/scripts/scenes/",
      "index": {
        "name": "app/scripts/scenes/index.js",
        "requirePath": "./"
      }
    }
  }
}

When I install all dependencies and run yarn start it runs ok, but gives me the following console error: Uncaught TypeError: Cannot read property 'sys' of null

rblopes commented 6 years ago

tl;dr workaround: edit the lines, near the end of the app/scripts/scenes/splash-screen.js module as follows:

 //  When the asset loader fulfills its job, start the Game scene.
 scene.load.on('complete', () => {
   this.scene
-    .remove(scene)
+    .stop(scene)
     .start('Game');
 });

This problem appeared after Phaser 3.5.0. There has been a big code refactor of the scene manager, changing how scenes are registered and initialized. A few things got broken during that refactor, but were restored in 3.5.1 after I filed an issue. Not all of them, though.

That exception occurs during the game initialization, on the splash screen game scene. In that scene, a new 'Loader' scene is created, at run-time, to load the remaining game assets while showing the progress bar graphic over the (sample) cover. When all assets finish loading, that scene is discarded.

It all happens in rapid succession in the sample game because of the few assets included being loaded, you may only catch a glimpse of the splash screen being replaced by the spinning Phaser logo. Provided you follow the convention proposed to declare game assets (using the assets.js module, still missing proper documentation :disappointed:), you should see the splash screen in action for a bit more time and the progress bar animating. Things won't improve with the addition of more game assets, however, because Phaser will not run that scene in time to initialize all its systems/managers.

I'll be looking for ways to fix the splash screen/loader combination before the next release of the generator. The whole thing feels too "hacky" and probably there are better ways to accomplish this without being too cryptic.

rblopes commented 6 years ago

Thanks for reporting this one.

Ended up with a cleaner solution, easier to follow and customize. The sample SplashScreen class will no longer rely on a parallel scene to load the game assets and the progress bar animation is just a sprite with a shape mask. No more magic!

Also removed the assets.js module in favor of the regular Loader API methods users are more familiar with. There are not much documentation yet on this feature in Phaser as well, it's probably better to take it out.

All commits on master branch.