mirror of
https://github.com/photonstorm/phaser
synced 2024-09-21 15:01:57 +00:00
Stage.backgroundColor now properly accepts hex #RRGGBB and color values 0xRRGGBB again (fix #785)
This commit is contained in:
parent
0bfa249ed5
commit
798d7a4fd1
4 changed files with 55 additions and 33 deletions
|
@ -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.
|
* 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)
|
* 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)
|
* 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
|
### 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.
|
* 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 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)
|
* 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
|
### To Do
|
||||||
|
|
|
@ -77,6 +77,5 @@ var Phaser = Phaser || {
|
||||||
|
|
||||||
// We don't need this in Pixi, so we've removed it to save space
|
// 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.
|
// 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.
|
// Ensure that an existing PIXI.InteractionManager is not overriden - in case you're using your own PIXI library.
|
||||||
|
PIXI.InteractionManager = PIXI.InteractionManager || function () {};
|
||||||
PIXI.InteractionManager = PIXI.InteractionManager || {};
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ Phaser.Stage = function (game, width, height) {
|
||||||
*/
|
*/
|
||||||
this.name = '_stage_root';
|
this.name = '_stage_root';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {boolean} interactive - Pixi level var, ignored by Phaser.
|
||||||
|
* @default
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this.interactive = false;
|
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
|
* @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)
|
Phaser.Stage.prototype.setBackgroundColor = function(backgroundColor)
|
||||||
{
|
{
|
||||||
// console.log('setBackgroundColor');
|
if (typeof backgroundColor === 'string')
|
||||||
this._backgroundColor = backgroundColor || 0x000000;
|
{
|
||||||
this.backgroundColorSplit = PIXI.hex2rgb(this.backgroundColor);
|
var rgb = Phaser.Color.hexToColor(backgroundColor);
|
||||||
var hex = this._backgroundColor.toString(16);
|
this._backgroundColor = Phaser.Color.getColor(rgb.r, rgb.g, rgb.b);
|
||||||
hex = '000000'.substr(0, 6 - hex.length) + hex;
|
}
|
||||||
this.backgroundColorString = '#' + hex;
|
else
|
||||||
// console.log(this._backgroundColor);
|
{
|
||||||
// console.log(this.backgroundColorSplit);
|
var rgb = Phaser.Color.getRGB(backgroundColor);
|
||||||
// console.log(hex);
|
this._backgroundColor = backgroundColor;
|
||||||
// console.log(this.backgroundColorString);
|
}
|
||||||
|
|
||||||
|
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", {
|
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
|
||||||
|
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|
||||||
return this._backgroundColor;
|
return this._backgroundColor;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function (color) {
|
set: function (color) {
|
||||||
|
|
||||||
this._backgroundColor = color;
|
if (!this.game.transparent)
|
||||||
|
|
||||||
if (this.game.transparent === false)
|
|
||||||
{
|
{
|
||||||
if (typeof color === 'string')
|
|
||||||
{
|
|
||||||
// console.log(color);
|
|
||||||
color = Phaser.Color.hexToRGB(color);
|
|
||||||
// console.log(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setBackgroundColor(color);
|
this.setBackgroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
* Alpha will only be set if it exist in the given color (0xAARRGGBB)
|
||||||
*
|
*
|
||||||
* @method Phaser.Color.getRGB
|
* @method Phaser.Color.getRGB
|
||||||
* @static
|
* @static
|
||||||
* @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).
|
* @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) {
|
getRGB: function (color) {
|
||||||
|
|
||||||
return {
|
if (color > 16777215)
|
||||||
alpha: color >>> 24,
|
{
|
||||||
red: color >> 16 & 0xFF,
|
// The color value has an alpha component
|
||||||
green: color >> 8 & 0xFF,
|
return {
|
||||||
blue: color & 0xFF
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue