Hex String to Color

Demonstrates how to convert CSS-style hexadecimal strings, in both 3-digit and 6-digit formats, into Phaser Color objects.

Hex String to Color, running
1024 × 768
GitHub
class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    create ()
    {

        const color1 = Phaser.Display.Color.HexStringToColor('#ff00ff');
        console.log(color1);

        const color2 = Phaser.Display.Color.HexStringToColor('#0155dd');
        console.log(color2);

        const color3 = Phaser.Display.Color.HexStringToColor('#03f');
        console.log(color3);

        const color4 = Phaser.Display.Color.HexStringToColor('#FFAAEE');
        console.log(color4);
    }

}

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

const game = new Phaser.Game(config);

More in Color9 examples