Skip to content

Commit d026f96

Browse files
committed
You can now set the Stage.backgroundColor using either hex or numeric values.
1 parent cfa2c96 commit d026f96

4 files changed

Lines changed: 54 additions & 11 deletions

File tree

examples/wip/anim1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function preload() {
99

1010
function create() {
1111

12+
// game.stage.backgroundColor = '#239923';
13+
game.stage.backgroundColor = 0xff8855;
14+
1215
var mummy = game.add.sprite(300, 200, 'mummy', 5);
1316

1417
mummy.animations.add('walk');

examples/wip/text tilesprite.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
// var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
3-
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
3+
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
44

55
function preload() {
66

@@ -13,6 +13,7 @@ var font;
1313
var i;
1414
var background;
1515
var filter;
16+
var count = 0;
1617

1718
function create() {
1819

@@ -27,23 +28,33 @@ function create() {
2728
background.filters = [filter];
2829

2930
font = game.add.bitmapFont('knightHawks', 31, 25, Phaser.BitmapFont.TEXT_SET6, 10, 1, 1);
30-
font.text = 'phaser was here';
31+
font.text = 'phaser ';
3132

32-
i = game.add.image(0, 0, font);
33+
// i = game.add.image(0, 0, font);
3334

34-
// sprite = game.add.tileSprite(0, 0, 800, 600, font);
35+
sprite = game.add.tileSprite(0, 0, 800, 600, font);
3536

3637
}
3738

3839
function update() {
3940

41+
count += 0.005
42+
43+
sprite.tileScale.x = 2 + Math.sin(count);
44+
sprite.tileScale.y = 2 + Math.cos(count);
45+
46+
sprite.tilePosition.x += 1;
47+
sprite.tilePosition.y += 1;
48+
49+
4050
// game.camera.view.x++;
4151

4252
filter.update();
4353

4454
// Uncomment for coolness :)
4555
// filter.blueShift -= 0.001;
4656

47-
// font.text = "phaser x: " + game.input.x + " y: " + game.input.y;
57+
font.text = " phaser x: " + game.input.x + " y: " + game.input.y;
58+
sprite.refreshTexture = true;
4859

4960
}

src/core/Stage.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Phaser.Stage = function (game, width, height) {
6161
*/
6262
this._nextOffsetCheck = 0;
6363

64+
/**
65+
* @property {number} _backgroundColor - Stage background color.
66+
* @private
67+
*/
68+
this._backgroundColor;
69+
6470
if (game.config)
6571
{
6672
this.parseConfig(game.config);
@@ -275,11 +281,26 @@ Phaser.Stage.prototype.visibilityChange = function (event) {
275281

276282
}
277283

284+
/**
285+
* Sets the background color for the stage.
286+
*
287+
* @name Phaser.Stage#setBackgroundColor
288+
* @param {number} backgroundColor - The color of the background, easiest way to pass this in is in hex format like: 0xFFFFFF for white.
289+
*/
290+
Phaser.Stage.prototype.setBackgroundColor = function(backgroundColor)
291+
{
292+
this._backgroundColor = backgroundColor || 0x000000;
293+
this.backgroundColorSplit = PIXI.hex2rgb(this.backgroundColor);
294+
var hex = this._backgroundColor.toString(16);
295+
hex = '000000'.substr(0, 6 - hex.length) + hex;
296+
this.backgroundColorString = '#' + hex;
297+
}
298+
278299
/**
279300
* @name Phaser.Stage#backgroundColor
280301
* @property {number|string} backgroundColor - Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000'
281302
*/
282-
Object.defineProperty(Phaser.Stage.prototype, "NEWbackgroundColor", {
303+
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
283304

284305
get: function () {
285306
return this._backgroundColor;

src/pixi/extras/TilingSprite.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,17 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
408408
{
409409
if(isFrame)
410410
{
411-
targetWidth = frame.width;
412-
targetHeight = frame.height;
413-
411+
if (texture.trim)
412+
{
413+
targetWidth = texture.trim.width;
414+
targetHeight = texture.trim.height;
415+
}
416+
else
417+
{
418+
targetWidth = frame.width;
419+
targetHeight = frame.height;
420+
}
421+
414422
newTextureRequired = true;
415423

416424
}
@@ -443,7 +451,7 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
443451
this.tilingTexture.isTiling = true;
444452

445453
}
446-
454+
447455
canvasBuffer.context.drawImage(texture.baseTexture.source,
448456
frame.x,
449457
frame.y,

0 commit comments

Comments
 (0)