diff --git a/README.md b/README.md index 37c853e68..9cfc40290 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Version 2.0.5 - "Tanchico" - in development * Math.interpolateAngles and Math.nearestAngleBetween have been removed for the time being. They threw run-time errors previously. * PIXI.InteractionManager is no longer over-written if the object already exists (thanks @georgiee, #818) * Key.justPressed and justReleased incorrectly set the delay value to 2500ms. Now defaults to 50ms (thanks @draklaw, fix #797) +* Stage.backgroundColor can now accept short-code hex values: `#222`, `#334`, etc. ### New Features @@ -115,6 +116,7 @@ Version 2.0.5 - "Tanchico" - in development * RandomDataGenerator.integerInRange would return a non-integer value if you passed in a float. * Timer class updated so that code-resumed pauses don't mess up the internal _pausedTotal value (thanks @joelrobichaud, fix #814) * Timer class when paused by code after a game-level pause wouldn't set the codepaused flag (thanks @joelrobichaud, fix #814) +* Stage.backgroundColor now properly accepts hex #RRGGBB and color values 0xRRGGBB again (fix #785) ### To Do diff --git a/src/Phaser.js b/src/Phaser.js index 82e0daf7d..8797942aa 100644 --- a/src/Phaser.js +++ b/src/Phaser.js @@ -77,6 +77,5 @@ var Phaser = Phaser || { // We don't need this in Pixi, so we've removed it to save space // however the Stage object expects a reference to it, so here is a dummy entry. -// Ensure that an existing PIXI.InteractionManager is not overriden- in case you're using your own PIXI library. - -PIXI.InteractionManager = PIXI.InteractionManager || {}; +// Ensure that an existing PIXI.InteractionManager is not overriden - in case you're using your own PIXI library. +PIXI.InteractionManager = PIXI.InteractionManager || function () {}; diff --git a/src/core/Stage.js b/src/core/Stage.js index d8a415959..61555afa4 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -35,6 +35,11 @@ Phaser.Stage = function (game, width, height) { */ this.name = '_stage_root'; + /** + * @property {boolean} interactive - Pixi level var, ignored by Phaser. + * @default + * @private + */ this.interactive = false; /** @@ -334,23 +339,27 @@ Phaser.Stage.prototype.visibilityChange = function (event) { }; /** -* Sets the background color for the stage. +* Sets the background color for the Stage. The color can be given as a hex value (#RRGGBB) or a numeric value (0xRRGGBB) * * @name Phaser.Stage#setBackgroundColor -* @param {number} backgroundColor - The color of the background, easiest way to pass this in is in hex format like: 0xFFFFFF for white. +* @param {number|string} backgroundColor - The color of the background. */ Phaser.Stage.prototype.setBackgroundColor = function(backgroundColor) { - // console.log('setBackgroundColor'); - this._backgroundColor = backgroundColor || 0x000000; - this.backgroundColorSplit = PIXI.hex2rgb(this.backgroundColor); - var hex = this._backgroundColor.toString(16); - hex = '000000'.substr(0, 6 - hex.length) + hex; - this.backgroundColorString = '#' + hex; - // console.log(this._backgroundColor); - // console.log(this.backgroundColorSplit); - // console.log(hex); - // console.log(this.backgroundColorString); + if (typeof backgroundColor === 'string') + { + var rgb = Phaser.Color.hexToColor(backgroundColor); + this._backgroundColor = Phaser.Color.getColor(rgb.r, rgb.g, rgb.b); + } + else + { + var rgb = Phaser.Color.getRGB(backgroundColor); + this._backgroundColor = backgroundColor; + } + + this.backgroundColorSplit = [ rgb.r / 255, rgb.g / 255, rgb.b / 255 ]; + this.backgroundColorString = Phaser.Color.RGBtoString(rgb.r, rgb.g, rgb.b, 255, '#'); + }; /** @@ -360,22 +369,15 @@ Phaser.Stage.prototype.setBackgroundColor = function(backgroundColor) Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", { get: function () { + return this._backgroundColor; + }, set: function (color) { - this._backgroundColor = color; - - if (this.game.transparent === false) + if (!this.game.transparent) { - if (typeof color === 'string') - { - // console.log(color); - color = Phaser.Color.hexToRGB(color); - // console.log(color); - } - this.setBackgroundColor(color); } diff --git a/src/utils/Color.js b/src/utils/Color.js index 1e43b15f6..c3c9e2275 100644 --- a/src/utils/Color.js +++ b/src/utils/Color.js @@ -751,23 +751,42 @@ Phaser.Color = { }, /** - * Return the component parts of a color as an Object with the properties alpha, red, green, blue + * Return the component parts of a color as an Object with the properties alpha, red, green, blue. * * Alpha will only be set if it exist in the given color (0xAARRGGBB) * * @method Phaser.Color.getRGB * @static * @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB). - * @returns {object} An Object with properties: alpha, red, green, blue. + * @returns {object} An Object with properties: alpha, red, green, blue (also r, g, b and a). Alpha will only be present if a color value > 16777215 was given. */ getRGB: function (color) { - return { - alpha: color >>> 24, - red: color >> 16 & 0xFF, - green: color >> 8 & 0xFF, - blue: color & 0xFF - }; + if (color > 16777215) + { + // The color value has an alpha component + return { + alpha: color >>> 24, + red: color >> 16 & 0xFF, + green: color >> 8 & 0xFF, + blue: color & 0xFF, + a: color >>> 24, + r: color >> 16 & 0xFF, + g: color >> 8 & 0xFF, + b: color & 0xFF + }; + } + else + { + return { + red: color >> 16 & 0xFF, + green: color >> 8 & 0xFF, + blue: color & 0xFF, + r: color >> 16 & 0xFF, + g: color >> 8 & 0xFF, + b: color & 0xFF + }; + } },