Skip to content

Commit a4c5fb9

Browse files
committed
BitmapData.drawGroup can now handle drawing Emitters and BitmapText objects that are part of the Group.
1 parent 3b686f9 commit a4c5fb9

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
298298
* Tilemap.getObjectIndex has been removed as it didn't work correctly in most cases, and it's easier to just scan the Tilemap.objects object directly anyway (#2242)
299299
* GameObject.revive will now set the health amount to 100 instead of 1, bringing it in-line with the `maxHealth` default value.
300300
* Moved the Sound.disconnect after the Sound.stop call in Web Audio (#2280)
301+
* BitmapData.drawGroup can now handle drawing Emitters and BitmapText objects that are part of the Group.
301302

302303
### Bug Fixes
303304

src/gameobjects/BitmapData.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ Phaser.BitmapData.prototype = {
14271427

14281428
/**
14291429
* Draws the immediate children of a Phaser.Group to this BitmapData.
1430-
* Children are only drawn if they have their `exists` property set to `true`.
1430+
* Children are only drawn if they have their `exists` property set to `true` and have image based Textures.
14311431
* The children will be drawn at their `x` and `y` world space coordinates. If this is outside the bounds of the BitmapData they won't be drawn.
14321432
* When drawing it will take into account the child's rotation, scale and alpha values.
14331433
* No iteration takes place. Groups nested inside other Groups will not be iterated through.
@@ -1442,13 +1442,38 @@ Phaser.BitmapData.prototype = {
14421442

14431443
if (group.total > 0)
14441444
{
1445-
group.forEachExists(this.copy, this, null, null, null, null, null, null, null, null, null, null, null, null, null, null, blendMode, roundPx);
1445+
group.forEachExists(this.drawGroupProxy, this, blendMode, roundPx);
14461446
}
14471447

14481448
return this;
14491449

14501450
},
14511451

1452+
/**
1453+
* A proxy for drawGroup that handles child iteration for more complex Game Objects.
1454+
*
1455+
* @method Phaser.BitmapData#drawGroupProxy
1456+
* @private
1457+
* @param {Phaser.Sprite|Phaser.Image|Phaser.BitmapText} child - The child to draw.
1458+
* @param {string} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
1459+
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
1460+
*/
1461+
drawGroupProxy: function (child, blendMode, roundPx) {
1462+
1463+
if (child.type === Phaser.EMITTER || child.type === Phaser.BITMAPTEXT)
1464+
{
1465+
for (var i = 0; i < child.children.length; i++)
1466+
{
1467+
this.copy(child.children[i], null, null, null, null, null, null, null, null, null, null, null, null, null, null, blendMode, roundPx);
1468+
}
1469+
}
1470+
else
1471+
{
1472+
this.copy(child, null, null, null, null, null, null, null, null, null, null, null, null, null, null, blendMode, roundPx);
1473+
}
1474+
1475+
},
1476+
14521477
/**
14531478
* Draws the Game Object or Group to this BitmapData and then recursively iterates through all of its children.
14541479
*

0 commit comments

Comments
 (0)