Convert RGB Strings to Color Objects
Demonstrates how to parse CSS-style RGB and RGBA strings into Phaser Color objects, including handling of alpha channels and out-of-range values.
1024 × 768
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
create() {
const color1 = Phaser.Display.Color.RGBStringToColor('rgb(255, 155, 55)');
console.log(color1);
const color2 = Phaser.Display.Color.RGBStringToColor('rgba(255, 155, 55, 0.5)');
console.log(color2);
const color3 = Phaser.Display.Color.RGBStringToColor('rgba(345, 50, 100, 2.5)');
console.log(color3);
const color4 = Phaser.Display.Color.RGBStringToColor('rgb(50, -50, 50)');
console.log(color4);
const color5 = Phaser.Display.Color.RGBStringToColor('RGB(255, 0, 255)');
console.log(color5);
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);