This is a post on the phaser color class that has a whole bunch of static methods that can be helpful for color conversion. This class is helpful for say converting a color value like 0x00ff00 to ‘rgba(0,255,0,1)’, which can be helpful for making quick work of this without wasting time writing such methods from the ground up, or copying and pasting a solution for stack overflow. There is of course no need for that if a solution is in the framework itself, and this is the case with phaser.
As of this writing I am using phaser 2.11.0 when making this demo. In other words what is now known as Phaser Community Edition. So far I have not made the switch to Phaser 3, and I do not plan on doing so any time soon, as long as Phaser CE is still supported.
In this section I will be covering some must know methods in Phaser.Color.
The getWebRgb Method of the Color class is one of the methods that comes in handy when working with color in a phaser project. Often I am working with plain canvas, and some methods in phaser can accept a canvas as an argument. So there is a need to convert a phaser friendly color to a canvas friendly color, quickly. This is where getWebRgb comes in handy.
So this method can be used to quickly convert an integer color value to a web friendly rgba color string. No need to hunt down a solution for this, yet alone make you r own from the ground up with this, there is a method in the framework itself.
Want to quickly convert an rgb, or rgba color string to an object with red, grenn ,blue, and alpha values. Then The webRGB method can be used to make quick work of that.
This helps to keep me from making some kind of overly complex vanilla js solution for this.