From 003403c832b8b9e927fd4156dd49a0da116a0190 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 9 Jul 2014 11:15:24 +0100 Subject: [PATCH] Color.getWebRGB will now accept either an Object or numeric color value. --- README.md | 1 + build/phaser.d.ts | 2 +- src/utils/Color.js | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dfde0c87a..e731653f9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build/phaser.d.ts b/build/phaser.d.ts index f09c55d6b..48e3d05dc 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -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; diff --git a/src/utils/Color.js b/src/utils/Color.js index a6f4b7a0a..da366a395 100644 --- a/src/utils/Color.js +++ b/src/utils/Color.js @@ -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() + ')'; + } },