From ba74bea4b4dbfd8ca8064c83cb856fd534d97e68 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Mon, 30 Dec 2013 21:36:50 +0000 Subject: [PATCH] New Group.destroy example and patched the desyrel font xml. --- README.md | 4 ++ examples/assets/fonts/desyrel.xml | 2 +- .../{groups => input}/bring a child to top.js | 0 examples/wip/group destroy.js | 54 +++++++++++++++++++ src/core/Group.js | 46 ++++++++++++++-- src/gameobjects/BitmapText.js | 9 +--- 6 files changed, 103 insertions(+), 12 deletions(-) rename examples/{groups => input}/bring a child to top.js (100%) create mode 100644 examples/wip/group destroy.js diff --git a/README.md b/README.md index 7fb62753..973a8f73 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ Updates: * You can now collide a group against itself, to have all children collide, and bodies won't check against themselves (thanks cocoademon) * RenderTexture.render / renderXY has a new parameter: renderHidden, a boolean which will allow you to render Sprites even if their visible is set to false. * Added in prototype.constructor definitions to every class (thanks darkoverlordofdata) +* Group.destroy has a new parameter: destroyChildren (boolean) which will optionally call the destroy method of all Group children. Bug Fixes: @@ -124,6 +125,8 @@ Bug Fixes: * RenderTexture now displays correctly in Canvas games. * Canvas.addToDOM is now more robust when applying the overflowHidden style. * Fixed Pixi.StripShader which should stop the weird TileSprite GPU issues some were reporting (thanks GoodboyDigital) +* Patched desyrel.xml so it doesn't contain any zero width/height characters, as they broke Firefox 25. + You can view the Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md @@ -291,6 +294,7 @@ Beyond version 1.2 * Create more touch input examples (http://www.html5gamedevs.com/topic/1556-mobile-touch-event/) * Look at HiDPI Canvas settings. * Support for parallel asset loading. +* Fixed width bitmap font support, plus enhanced Bitmap font rendering. Contributing diff --git a/examples/assets/fonts/desyrel.xml b/examples/assets/fonts/desyrel.xml index 54fcdbba..9919ad35 100644 --- a/examples/assets/fonts/desyrel.xml +++ b/examples/assets/fonts/desyrel.xml @@ -99,7 +99,7 @@ - + diff --git a/examples/groups/bring a child to top.js b/examples/input/bring a child to top.js similarity index 100% rename from examples/groups/bring a child to top.js rename to examples/input/bring a child to top.js diff --git a/examples/wip/group destroy.js b/examples/wip/group destroy.js new file mode 100644 index 00000000..54ac0d4c --- /dev/null +++ b/examples/wip/group destroy.js @@ -0,0 +1,54 @@ +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); + +function preload() { + + game.load.image('atari1', 'assets/sprites/atari130xe.png'); + game.load.image('atari2', 'assets/sprites/atari800xl.png'); + game.load.image('atari4', 'assets/sprites/atari800.png'); + game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); + game.load.image('duck', 'assets/sprites/darkwing_crazy.png'); + game.load.image('firstaid', 'assets/sprites/firstaid.png'); + game.load.image('diamond', 'assets/sprites/diamond.png'); + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); + +} + +var group; +var sprite; + +function create() { + + var images = game.cache.getImageKeys(); + + group = game.add.group(); + + for (var i = 0; i < 20; i++) + { + sprite = group.create(game.world.randomX, game.world.randomY, game.rnd.pick(images)); + } + + sprite.x = 100; + sprite.y = 100; + + game.add.tween(sprite).to( { y: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true); + + game.input.onDown.addOnce(nuke, this); + +} + +function nuke() { + + // The optional parameter here will destroy the Sprites as well as the Group. + // The default is 'false' which means destroy the Group, but none of the children. + group.destroy(true); + + console.log(group); + console.log(sprite); + +} + +function render() { + + game.debug.renderText('Click to nuke', 32, 32); + +} \ No newline at end of file diff --git a/src/core/Group.js b/src/core/Group.js index 4ea2eb0d..8763afff 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -1338,11 +1338,31 @@ Phaser.Group.prototype = { * Destroys this Group. Removes all children, then removes the container from the display list and nulls references. * * @method Phaser.Group#destroy + * @param {boolean} [destroyChildren=false] - Should every child of this Group have its destroy method called? */ - destroy: function () { + destroy: function (destroyChildren) { - this.removeAll(); + if (typeof destroyChildren === 'undefined') { destroyChildren = false; } + if (destroyChildren) + { + if (this._container.children.length > 0) + { + do + { + if (this._container.children[0].group) + { + this._container.children[0].destroy(); + } + } + while (this._container.children.length > 0); + } + } + else + { + this.removeAll(); + } + this._container.parent.removeChild(this._container); this._container = null; @@ -1505,7 +1525,16 @@ Phaser.Group.prototype.constructor = Phaser.Group; Object.defineProperty(Phaser.Group.prototype, "total", { get: function () { - return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); + + if (this._container) + { + return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); + } + else + { + return 0; + } + } }); @@ -1518,7 +1547,16 @@ Object.defineProperty(Phaser.Group.prototype, "total", { Object.defineProperty(Phaser.Group.prototype, "length", { get: function () { - return this._container.children.length; + + if (this._container) + { + return this._container.children.length; + } + else + { + return 0; + } + } }); diff --git a/src/gameobjects/BitmapText.js b/src/gameobjects/BitmapText.js index 2ccece4b..a60d66eb 100644 --- a/src/gameobjects/BitmapText.js +++ b/src/gameobjects/BitmapText.js @@ -120,11 +120,6 @@ Phaser.BitmapText = function (game, x, y, text, style) { this._cache.x = this.x; this._cache.y = this.y; - /** - * @property {boolean} renderable - A renderable object will be rendered to the context each frame. - */ - this.renderable = true; - }; Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype); @@ -153,8 +148,8 @@ Phaser.BitmapText.prototype.update = function() { this._cache.dirty = true; } - this.pivot.x = this.anchor.x*this.width; - this.pivot.y = this.anchor.y*this.height; + this.pivot.x = this.anchor.x * this.width; + this.pivot.y = this.anchor.y * this.height; }