Scene From Class

Demonstrates how to define a Scene using the Phaser.Class factory method, including extending the base Scene and implementing standard lifecycle methods like preload and create.

Scene From Class, running
800 × 600
GitHub
const MyScene = new Phaser.Class({

    Extends: Phaser.Scene,

    initialize:

    function MyScene (config)
    {
        Phaser.Scene.call(this, config)
    },

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

    create: function ()
    {
        this.face = this.add.image(400, 300, 'face');
    }

});

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.WEBGL,
    width: 800,
    height: 600,
    backgroundColor: '#000000',
    parent: 'game-container',
    scene: MyScene
};

const game = new Phaser.Game(config);

More in Scenes52 examples