Skip to content

Commit 003403c

Browse files
committed
Color.getWebRGB will now accept either an Object or numeric color value.
1 parent 2293b64 commit 003403c

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Version 2.0.6 - "Jornhill" - -in development-
133133
* You can now debug render Ninja Physics AABB and Circle objects (thanks @psalaets, #972)
134134
* Phaser.Utils.mixin will mix the source object into the destination object, returning the newly modified destination object.
135135
* You can now use `game.add.plugin` from the GameObjectFactory (thanks @alvinsight, #978)
136+
* Color.getWebRGB will now accept either an Object or numeric color value.
136137

137138

138139
### Bug Fixes

build/phaser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ declare module Phaser {
14921492
static getRandomColor(min?: number, max?: number, alpha?: number): number;
14931493
static getRed(color: number): number;
14941494
static getRGB(color: number): Object;
1495-
static getWebRGB(color: number): string;
1495+
static getWebRGB(color: any): string;
14961496
static hexToRGB(h: string): number;
14971497
static hexToColor(hex: string, out?: Object): Object;
14981498
static HSLtoRGB(h: number, s: number, l: number, out?: Object): Object;

src/utils/Color.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,20 @@ Phaser.Color = {
798798
*
799799
* @method Phaser.Color.getWebRGB
800800
* @static
801-
* @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).
801+
* @param {number|Object} color - Color in RGB (0xRRGGBB), ARGB format (0xAARRGGBB) or an Object with r, g, b, a properties.
802802
* @returns {string} A string in the format: 'rgba(r,g,b,a)'
803803
*/
804804
getWebRGB: function (color) {
805805

806-
var rgb = Phaser.Color.getRGB(color);
807-
808-
return 'rgba(' + rgb.r.toString() + ',' + rgb.g.toString() + ',' + rgb.b.toString() + ',' + rgb.a.toString() + ')';
806+
if (typeof color === 'object')
807+
{
808+
return 'rgba(' + color.r.toString() + ',' + color.g.toString() + ',' + color.b.toString() + ',' + (color.a / 255).toString() + ')';
809+
}
810+
else
811+
{
812+
var rgb = Phaser.Color.getRGB(color);
813+
return 'rgba(' + rgb.r.toString() + ',' + rgb.g.toString() + ',' + rgb.b.toString() + ',' + (rgb.a / 255).toString() + ')';
814+
}
809815

810816
},
811817

0 commit comments

Comments
 (0)