Open TomYeoman opened 2 years ago
I found a workaround using this.game.plugins.installScenePlugin
Remove plugins from game config:
const config = {
type: Phaser.HEADLESS,
width: 512,
height: 512,
banner: false,
audio: false,
scene: [MainScene],
fps: {
target: FPS
},
physics: {
default: 'matter',
matter: {
debug: false,
gravity: { y: 0 },
}
},
}
and at my MainScene#preload I did this:
const PhaserMatterCollisionPlugin = require('phaser-matter-collision-plugin')
module.exports = class MainScene extends Phaser.Scene {
constructor() {
super('MainScene')
}
preload() {
this.game.plugins.installScenePlugin('matterCollision', PhaserMatterCollisionPlugin.default, 'matterCollision', this);
this.matterCollision.start()
}
Call start method is very important without it the colliders won't work.
Perfect worked a charm! Thanks very much @xptavares
Just stumbled upon this bug while developing a plugin for Phaser and it took me a few hours to realise this is a bug in Phaser on NodeJS.
Any idea where the bug could be?
UPDATE: I looked into it a little more and it looks like plugins are in fact loading and being started, but only AFTER the whole game has booted and the first scene started, whereas on the web the plugins are all part of the boot process before any scene is started.
One workaround I found for starting the game with plugins loaded is to not add any in the global config and instead start the first scene through the game object:
const game = new Phaser.Game(config);
game.scene.add("SampleScene", SampleScene, true)
The downside, aside from being unintuitive, is that the __SYSTEM
scene will not have any plugins installed
Another workaround, not sure whether it's any better:
const config: GameConfig = {
...
callbacks: {
preBoot: BROWSER ? undefined : (game) => {
// The existing plugin manager is booted too late in the process when running in headless mode, but we can not
// explicitly boot it, and it's not safe to override it, because it's already hooked into the game's boot event.
// Instead, we give the existing plugin manager some dummy objects to work on, and then replace it with a new one
// that gets booted immediately.
// @ts-ignore
game.plugins.game = {config: new Config(), events: new EventEmitter()};
game.plugins = new PluginManager(game);
}
},
scene: [SampleScene]
};
The downside of this approach is that whatever the global plugins do with the plugin manager instance (e.g. installing scene plugins) gets lost...
Describe the bug
Loving the project so far, thanks for keeping it up to date. I may be missing something but it seems plugins are not working for now -
Using the following code -
I then use in the scene as such -
However review the following error -