Bring to Top

Demonstrates how to move a specific item to the end of an array using the BringToTop utility function.

Bring to Top, running
1024 × 768
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        const data = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ];

        this.add.text(10, 10, `Before: ${data.join(' - ')}`, { font: '16px Courier', fill: '#00ff00' });

        Phaser.Utils.Array.BringToTop(data, 'c');

        this.add.text(10, 40, `After:  ${data.join(' - ')}`, { font: '16px Courier', fill: '#00ff00' });
    }
}

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

const game = new Phaser.Game(config);

More in Array10 examples