lean / phaser-es6-webpack

A bootstrap project for create games with Phaser + ES6 + Webpack.
MIT License
1.28k stars 319 forks source link

game is not an instance of Phaser.Game #64

Closed tobspr closed 6 years ago

tobspr commented 6 years ago

When trying the typescript branch, I got the following error:

phaser-split.js:24791 Uncaught Error: The value passed as the `game` argument ([object Object]) is not an instance of Phaser.Game.

The error happens at the Mushroom class:

export default class extends Phaser.Sprite {
  constructor ({ game, x, y, asset }) {
    super(game, x, y, asset) 
    this.anchor.setTo(0.5)
  }

When inspecting game, it looks like game is an instance of Phaser.Game, which was very weird. Also, comparing game.__proto__ to Phaser.Game.prototype looked the same. However, game.__proto__ == Phaser.Game.prototype yields false, which is why the check fails.

It seems that the import Phaser from 'phaser' import causes the problem. When using import Phaser from 'phaser-ce' it works, at least for me, since its picking up the correct class then.

lean commented 6 years ago

that branch is unmaintained, please, feel free to update

Fusyong commented 5 years ago

in my case, a change in Game.js will do it:

this.mushroom = new Mushroom({
      // from
      // game: this,  
      // to:
      game: this.game,  
      x: this.world.centerX,
      y: this.world.centerY,
      asset: 'mushroom'
})