rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 262 forks source link

Phaser 3.60.0 don't work,error "ReferenceError: Phaser is not defined at IsSceneObject.js:1:20" #439

Closed cydd007 closed 3 months ago

cydd007 commented 3 months ago

import RexUIPlugin from 'phaser3-rex-plugins/templates/ui/ui-plugin.js'; class GameScene extends Phaser.Scene {

constructor(config:any) { super(config); } preload(){} create(){}

} var config:Phaser.Types.Core.GameConfig = { type: Phaser.AUTO, width: width, height: height, plugins: { scene: [ { key: 'rexUI', plugin: RexUIPlugin, mapping: 'rexUI'} ] }, physics: { default: 'arcade', arcade: { gravity: {y: 200 }, debug: false } }, scale: { width: width, height: height, mode: Scale.CENTER_BOTH , },

  scene: GameScene,

};

let phaserGame = new Phaser.Game(config);

When I am running in the browser,console error:

"ReferenceError: Phaser is not defined at IsSceneObject.js:1:20"

when i use this config: var config:Phaser.Types.Core.GameConfig = { type: Phaser.AUTO, width: width, height: height, physics: { default: 'arcade', arcade: { gravity: {y: 200 }, debug: false } }, scale: { width: width, height: height, mode: Scale.CENTER_BOTH , },

  scene: GameScene,

};

My program is running normally,Why?

rexrainbow commented 3 months ago

Import phaser before rexUI package. Once phaser is imported, it will run window.Phaser = Phaser, therefore rexUI can get reference of phaser module. Please check that window.Phaser is valid. Bundle toolchain might not export that instruction.

cydd007 commented 3 months ago

import RexUIPlugin from 'phaser3-rex-plugins/templates/ui/ui-plugin.js'; import Phaser from 'phaser';

The import order is wrong,modify:

import Phaser from 'phaser'; import RexUIPlugin from 'phaser3-rex-plugins/templates/ui/ui-plugin.js';

It's running