Global Scene Plugin

Demonstrates how to register a global plugin in the game configuration and access its methods within a Scene using a custom property mapping.

Global Scene Plugin, running
800 × 600
GitHub
class TestPlugin extends Phaser.Plugins.BasePlugin {

    constructor (pluginManager)
    {
        super(pluginManager);
    }

    wibble ()
    {
        console.log('hello');
    }

}

var config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 800,
    height: 600,
    plugins: {
        global: [
            { key: 'TestPlugin', plugin: TestPlugin, start: false, mapping: 'test' }
        ]
    },
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
    this.load.image('elephant', 'assets/sprites/elephant.png');
}

function create ()
{
    this.test.wibble();
}

More in Plugins17 examples