Color.getWebRGB will now accept either an Object or numeric color value.

This commit is contained in:
photonstorm 2014-07-09 11:15:24 +01:00
parent 2293b64c94
commit 003403c832
3 changed files with 12 additions and 5 deletions

View file

@ -133,6 +133,7 @@ Version 2.0.6 - "Jornhill" - -in development-
* You can now debug render Ninja Physics AABB and Circle objects (thanks @psalaets, #972)
* Phaser.Utils.mixin will mix the source object into the destination object, returning the newly modified destination object.
* You can now use `game.add.plugin` from the GameObjectFactory (thanks @alvinsight, #978)
* Color.getWebRGB will now accept either an Object or numeric color value.
### Bug Fixes

2
build/phaser.d.ts vendored
View file

@ -1492,7 +1492,7 @@ declare module Phaser {
static getRandomColor(min?: number, max?: number, alpha?: number): number;
static getRed(color: number): number;
static getRGB(color: number): Object;
static getWebRGB(color: number): string;
static getWebRGB(color: any): string;
static hexToRGB(h: string): number;
static hexToColor(hex: string, out?: Object): Object;
static HSLtoRGB(h: number, s: number, l: number, out?: Object): Object;

View file

@ -798,14 +798,20 @@ Phaser.Color = {
*
* @method Phaser.Color.getWebRGB
* @static
* @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).
* @param {number|Object} color - Color in RGB (0xRRGGBB), ARGB format (0xAARRGGBB) or an Object with r, g, b, a properties.
* @returns {string} A string in the format: 'rgba(r,g,b,a)'
*/
getWebRGB: function (color) {
var rgb = Phaser.Color.getRGB(color);
return 'rgba(' + rgb.r.toString() + ',' + rgb.g.toString() + ',' + rgb.b.toString() + ',' + rgb.a.toString() + ')';
if (typeof color === 'object')
{
return 'rgba(' + color.r.toString() + ',' + color.g.toString() + ',' + color.b.toString() + ',' + (color.a / 255).toString() + ')';
}
else
{
var rgb = Phaser.Color.getRGB(color);
return 'rgba(' + rgb.r.toString() + ',' + rgb.g.toString() + ',' + rgb.b.toString() + ',' + (rgb.a / 255).toString() + ')';
}
},