Group Create Child

Demonstrates how to use the group.create method to instantiate a new Sprite and automatically add it to both the Group and the Scene display list.

Group Create Child, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('phaser', 'assets/sprites/phaser2.png');
    }

    create ()
    {
        const group = this.add.group();

        //  Create a Sprite via the group.

        //  The Sprite is added to the Scene display list, and to the group, at the same time.

        group.create(400, 300, 'phaser');

        //  The above is a short-cut for:
        //  var sprite = this.add.sprite(400, 300, 'phaser');
        //  group.add(sprite);
    }
}

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

const game = new Phaser.Game(config);

More in Group15 examples