Skip to content

Commit cc9a234

Browse files
committed
Color.getRGB would return incorrect color components if a color value without alpha was given, now works with both 0xRRGGBB and 0xAARRGGBB.
Color.getWebRGB now works regardless if you give an 0xRRGGBB or 0xAARRGGBB color value.
1 parent 798d7a4 commit cc9a234

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Version 2.0.5 - "Tanchico" - in development
117117
* Timer class updated so that code-resumed pauses don't mess up the internal _pausedTotal value (thanks @joelrobichaud, fix #814)
118118
* Timer class when paused by code after a game-level pause wouldn't set the codepaused flag (thanks @joelrobichaud, fix #814)
119119
* Stage.backgroundColor now properly accepts hex #RRGGBB and color values 0xRRGGBB again (fix #785)
120+
* Color.getRGB would return incorrect color components if a color value without alpha was given, now works with both 0xRRGGBB and 0xAARRGGBB.
121+
* Color.getWebRGB now works regardless if you give an 0xRRGGBB or 0xAARRGGBB color value.
120122

121123

122124
### To Do

src/utils/Color.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,11 @@ Phaser.Color = {
779779
else
780780
{
781781
return {
782+
alpha: 255,
782783
red: color >> 16 & 0xFF,
783784
green: color >> 8 & 0xFF,
784785
blue: color & 0xFF,
786+
a: 255,
785787
r: color >> 16 & 0xFF,
786788
g: color >> 8 & 0xFF,
787789
b: color & 0xFF
@@ -792,19 +794,17 @@ Phaser.Color = {
792794

793795
/**
794796
* Returns a CSS friendly string value from the given color.
797+
*
795798
* @method Phaser.Color.getWebRGB
796799
* @static
797-
* @param {number} color
798-
* @returns {string}A string in the format: 'rgba(r,g,b,a)'
800+
* @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).
801+
* @returns {string} A string in the format: 'rgba(r,g,b,a)'
799802
*/
800803
getWebRGB: function (color) {
801804

802-
var alpha = (color >>> 24) / 255;
803-
var red = color >> 16 & 0xFF;
804-
var green = color >> 8 & 0xFF;
805-
var blue = color & 0xFF;
805+
var rgb = Phaser.Color.getRGB(color);
806806

807-
return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')';
807+
return 'rgba(' + rgb.r.toString() + ',' + rgb.g.toString() + ',' + rgb.b.toString() + ',' + rgb.a.toString() + ')';
808808

809809
},
810810

0 commit comments

Comments
 (0)