Skip to content

Commit ba74bea

Browse files
committed
New Group.destroy example and patched the desyrel font xml.
1 parent ce4cf53 commit ba74bea

6 files changed

Lines changed: 103 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Updates:
107107
* You can now collide a group against itself, to have all children collide, and bodies won't check against themselves (thanks cocoademon)
108108
* 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.
109109
* Added in prototype.constructor definitions to every class (thanks darkoverlordofdata)
110+
* Group.destroy has a new parameter: destroyChildren (boolean) which will optionally call the destroy method of all Group children.
110111

111112

112113
Bug Fixes:
@@ -124,6 +125,8 @@ Bug Fixes:
124125
* RenderTexture now displays correctly in Canvas games.
125126
* Canvas.addToDOM is now more robust when applying the overflowHidden style.
126127
* Fixed Pixi.StripShader which should stop the weird TileSprite GPU issues some were reporting (thanks GoodboyDigital)
128+
* Patched desyrel.xml so it doesn't contain any zero width/height characters, as they broke Firefox 25.
129+
127130

128131

129132
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
291294
* Create more touch input examples (http://www.html5gamedevs.com/topic/1556-mobile-touch-event/)
292295
* Look at HiDPI Canvas settings.
293296
* Support for parallel asset loading.
297+
* Fixed width bitmap font support, plus enhanced Bitmap font rendering.
294298

295299

296300
Contributing

examples/assets/fonts/desyrel.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<char id="46" x="214" y="391" width="13" height="13" xoffset="3" yoffset="54" xadvance="11" page="0" chnl="0" letter="."/>
100100
<char id="95" x="228" y="391" width="46" height="12" xoffset="-2" yoffset="63" xadvance="35" page="0" chnl="0" letter="_"/>
101101
<char id="45" x="275" y="391" width="29" height="11" xoffset="9" yoffset="46" xadvance="34" page="0" chnl="0" letter="-"/>
102-
<char id="32" x="305" y="391" width="0" height="0" xoffset="23" yoffset="81" xadvance="23" page="0" chnl="0" letter="space"/>
102+
<char id="32" x="305" y="391" width="1" height="1" xoffset="23" yoffset="81" xadvance="23" page="0" chnl="0" letter="space"/>
103103
</chars>
104104
<kernings count="1816">
105105
<kerning first="102" second="102" amount="2"/>

examples/wip/group destroy.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
2+
3+
function preload() {
4+
5+
game.load.image('atari1', 'assets/sprites/atari130xe.png');
6+
game.load.image('atari2', 'assets/sprites/atari800xl.png');
7+
game.load.image('atari4', 'assets/sprites/atari800.png');
8+
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
9+
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
10+
game.load.image('firstaid', 'assets/sprites/firstaid.png');
11+
game.load.image('diamond', 'assets/sprites/diamond.png');
12+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
13+
14+
}
15+
16+
var group;
17+
var sprite;
18+
19+
function create() {
20+
21+
var images = game.cache.getImageKeys();
22+
23+
group = game.add.group();
24+
25+
for (var i = 0; i < 20; i++)
26+
{
27+
sprite = group.create(game.world.randomX, game.world.randomY, game.rnd.pick(images));
28+
}
29+
30+
sprite.x = 100;
31+
sprite.y = 100;
32+
33+
game.add.tween(sprite).to( { y: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
34+
35+
game.input.onDown.addOnce(nuke, this);
36+
37+
}
38+
39+
function nuke() {
40+
41+
// The optional parameter here will destroy the Sprites as well as the Group.
42+
// The default is 'false' which means destroy the Group, but none of the children.
43+
group.destroy(true);
44+
45+
console.log(group);
46+
console.log(sprite);
47+
48+
}
49+
50+
function render() {
51+
52+
game.debug.renderText('Click to nuke', 32, 32);
53+
54+
}

src/core/Group.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,31 @@ Phaser.Group.prototype = {
13381338
* Destroys this Group. Removes all children, then removes the container from the display list and nulls references.
13391339
*
13401340
* @method Phaser.Group#destroy
1341+
* @param {boolean} [destroyChildren=false] - Should every child of this Group have its destroy method called?
13411342
*/
1342-
destroy: function () {
1343+
destroy: function (destroyChildren) {
13431344

1344-
this.removeAll();
1345+
if (typeof destroyChildren === 'undefined') { destroyChildren = false; }
13451346

1347+
if (destroyChildren)
1348+
{
1349+
if (this._container.children.length > 0)
1350+
{
1351+
do
1352+
{
1353+
if (this._container.children[0].group)
1354+
{
1355+
this._container.children[0].destroy();
1356+
}
1357+
}
1358+
while (this._container.children.length > 0);
1359+
}
1360+
}
1361+
else
1362+
{
1363+
this.removeAll();
1364+
}
1365+
13461366
this._container.parent.removeChild(this._container);
13471367

13481368
this._container = null;
@@ -1505,7 +1525,16 @@ Phaser.Group.prototype.constructor = Phaser.Group;
15051525
Object.defineProperty(Phaser.Group.prototype, "total", {
15061526

15071527
get: function () {
1508-
return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL);
1528+
1529+
if (this._container)
1530+
{
1531+
return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL);
1532+
}
1533+
else
1534+
{
1535+
return 0;
1536+
}
1537+
15091538
}
15101539

15111540
});
@@ -1518,7 +1547,16 @@ Object.defineProperty(Phaser.Group.prototype, "total", {
15181547
Object.defineProperty(Phaser.Group.prototype, "length", {
15191548

15201549
get: function () {
1521-
return this._container.children.length;
1550+
1551+
if (this._container)
1552+
{
1553+
return this._container.children.length;
1554+
}
1555+
else
1556+
{
1557+
return 0;
1558+
}
1559+
15221560
}
15231561

15241562
});

src/gameobjects/BitmapText.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ Phaser.BitmapText = function (game, x, y, text, style) {
120120
this._cache.x = this.x;
121121
this._cache.y = this.y;
122122

123-
/**
124-
* @property {boolean} renderable - A renderable object will be rendered to the context each frame.
125-
*/
126-
this.renderable = true;
127-
128123
};
129124

130125
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
@@ -153,8 +148,8 @@ Phaser.BitmapText.prototype.update = function() {
153148
this._cache.dirty = true;
154149
}
155150

156-
this.pivot.x = this.anchor.x*this.width;
157-
this.pivot.y = this.anchor.y*this.height;
151+
this.pivot.x = this.anchor.x * this.width;
152+
this.pivot.y = this.anchor.y * this.height;
158153

159154
}
160155

0 commit comments

Comments
 (0)