Convert Value to Color

Demonstrates how to use Phaser.Display.Color.ValueToColor to convert various color formats—including hex numbers, hex strings, and CSS RGB strings—into Phaser Color objects.

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

    create() {

        //  All should equal Color 255, 238, 221 (alpha 255)
        const color1 = Phaser.Display.Color.ValueToColor(0xffeedd);
        console.log(color1);

        const color2 = Phaser.Display.Color.ValueToColor('#ffeedd');
        console.log(color2);

        const color3 = Phaser.Display.Color.ValueToColor('#fed');
        console.log(color3);

        const color4 = Phaser.Display.Color.ValueToColor('rgb(255, 238, 221)');
        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