Add Scene After Game Instance

Demonstrates how to dynamically add and start a Scene to a Phaser Game instance after it has been initialized, including passing data to the Scene's create method.

Add Scene After Game Instance, running
800 × 600
GitHub
class MyScene extends Phaser.Scene {

    constructor (config)
    {
        super(config);
    }

    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('face', 'assets/pics/bw-face.png');
    }

    create (data)
    {
        this.face = this.add.image(data.x, data.y, 'face');
    }

}

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

var game = new Phaser.Game(config);

game.scene.add('myScene', MyScene, true, { x: 400, y: 300 });

More in Scenes52 examples