Plugins
Scene Plugin
class MyPlugin extends Phaser.Plugins.ScenePlugin {
constructor(scene, pluginManager) {
super(scene, pluginManager);
this.scene = scene;
}
boot() {
const eventEmitter = this.systems.events;
eventEmitter.on('update', this.update, this);
eventEmitter.once('shutdown', this.shutdown, this);
}
update(time, delta) {
// Called every frame
}
shutdown() {
// Cleanup
}
myCustomMethod() {
console.log('Custom method called!');
}
}
// Register plugin
const config = {
plugins: {
scene: [
{ key: 'MyPlugin', plugin: MyPlugin, mapping: 'myPlugin' }
]
}
};
// Use in scene
this.myPlugin.myCustomMethod();
Global Plugin
class GlobalPlugin extends Phaser.Plugins.BasePlugin {
constructor(pluginManager) {
super(pluginManager);
}
start() {
// Called when plugin starts
}
stop() {
// Called when plugin stops
}
}
// Register
const config = {
plugins: {
global: [
{ key: 'GlobalPlugin', plugin: GlobalPlugin, start: true }
]
}
};
Best Practices
- Scene plugins per funzionalità specifiche scene
- Global plugins per funzionalità cross-scene
- Cleanup in shutdown/stop
- Usa mapping per accesso facile
