Plugin system

Introduction

Plugin system, built-in system of phaser.

  • Author: Richard Davey

Usage

Global plugin

Load plugin

  • Load plugin before any scene start
    In game configuration
    // import pluginKlass from '...';
    var config = {
        // ...
        plugins: {
            global: [
                {
                    key: key,
                    plugin: pluginKlass,
                    start: true
                    // mapping: memberName  // member name in each scene instance, optional
                },
                // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
    • pluginKlass : Class instance
  • Load plugin in scene
    scene.load.plugin(key, url, true);
    
    • url : File url or class instance.

Get instance

var pluginInst = scene.plugins.get(key);

Scene plugin

Load plugin

  • Load plugin before any scene start
    In game configuration
    // import pluginKlass from '...';
    var config = {
        // ...
        plugins: {
            scene: [
                {
                    key: key,
                    plugin: pluginKlass,
                    mapping: sceneKey     // member name in each scene instance
                },
                // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
    • pluginKlass : Class instance
  • Load plugin in scene
    scene.load.scenePlugin(key, url, systemKey, sceneKey);
    
    • url : File url or class instance.

Get instance

var pluginInst = scene[sceneKey];

Plugin cache

  • Has custom plugin
    var hasPlugin = Phaser.Plugins.PluginCache.hasCustom(key);