Bring To Top

Demonstrates how to move a Game Object to the front of the display list, ensuring it renders on top of all other objects in the Scene.

Bring To Top, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('block', 'assets/sprites/block.png');
    }

    create ()
    {
        //  Create a stack of blocks
        const group = this.make.group({ key: 'block', frameQuantity: 12 });
        Phaser.Actions.SetXY(group.getChildren(), 48, 500, 64, 0);

        this.input.on('pointerdown', function (pointer) {
            const child = this.children.getAt(0);
            child.y -= 32;

            this.children.bringToTop(child);

        }, this);
    }
}

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

const game = new Phaser.Game(config);

More in Depth Sorting8 examples