Destroying a Game Instance with Plugins

Demonstrates how to completely destroy a Phaser game instance that uses a custom plugin and then safely recreate it from scratch.

Destroying a Game Instance with Plugins, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.plugin('RandomNamePlugin', 'assets/loader-tests/RandomNamePlugin.js', true);
    }

    create ()
    {
        let plugin = this.plugins.get('RandomNamePlugin');

        let names = plugin.getNames(10);

        names.push('', 'Click to destroy game instance');

        this.add.text(10, 10, names, { font: '16px Courier', fill: '#00ff00' });

        this.input.on('pointerdown', function ()
        {

            this.sys.game.destroy(true);

            document.addEventListener('mousedown', function newGame ()
            {

                game = new Phaser.Game(config);

                document.removeEventListener('mousedown', newGame);

            });

        }, this);
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 800,
    height: 600,
    scene: Example
};

let game = new Phaser.Game(config);

More in Plugins17 examples