Custom Image Class with ES6

Demonstrates how to create a custom game object by extending the Image class using ES6 syntax and adding instances to the scene.

Custom Image Class with ES6, running
1024 × 768
GitHub
class EnemyRobot extends Phaser.GameObjects.Image {

    constructor (scene, x, y)
    {
        super(scene, x, y);

        this.setTexture('contra');
        this.setPosition(x, y);
        this.setScale(2);
    }

}

var config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

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

function create ()
{
    this.children.add(new EnemyRobot(this, 264, 250));
    this.children.add(new EnemyRobot(this, 464, 350));
    this.children.add(new EnemyRobot(this, 664, 450));
}

More in Images16 examples