Skip to content

Commit 7411313

Browse files
committed
BitmapData.drawGroup draws the immediate children of a Phaser.Group to a BitmapData. Children are only drawn if they have their exists property set to true. The children will be drawn at their x and y world space coordinates. When drawing it will take into account the child's rotation, scale and alpha values. No iteration takes place. Groups nested inside other Groups will not be iterated through.
BitmapData.copy `tx` parameter if `null` and `source` is a Display Object, it will default to `source.x`. BitmapData.copy `ty` parameter if `null` and `source` is a Display Object, it will default to `source.y`.
1 parent 4a27130 commit 7411313

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Version 2.2.2 - "Alkindar" - in development
7878
* Line.normalAngle gets the angle of the line normal in radians.
7979
* Line.normalX and Line.normalY contain the x and y components of the left-hand normal of the line.
8080
* Line.fromAngle will sets this line to start at the given `x` and `y` coordinates and for the segment to extend at `angle` for the given `length`.
81+
* BitmapData.drawGroup draws the immediate children of a Phaser.Group to a BitmapData. Children are only drawn if they have their `exists` property set to `true`. The children will be drawn at their `x` and `y` world space coordinates. When drawing it will take into account the child's rotation, scale and alpha values. No iteration takes place. Groups nested inside other Groups will not be iterated through.
8182

8283
### Updates
8384

@@ -94,6 +95,8 @@ Version 2.2.2 - "Alkindar" - in development
9495
* Particles.Arcade.Emitter.emitParticle now returns a boolean depending if a particle was emitted or not.
9596
* Particles.Arcade.Emitter.update only updates `_counter` if a particle was successfully emitted.
9697
* Phaser.Point.angleSq removed. It didn't work so any code relying on it would be broken, and it's unclear what it was meant for (thanks @nextht #1396)
98+
* BitmapData.copy `tx` parameter if `null` and `source` is a Display Object, it will default to `source.x`.
99+
* BitmapData.copy `ty` parameter if `null` and `source` is a Display Object, it will default to `source.y`.
97100

98101
### Bug Fixes
99102

src/gameobjects/BitmapData.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,8 @@ Phaser.BitmapData.prototype = {
969969
* @param {number} [y=0] - The y coordinate representing the top-left of the region to copy from the source image.
970970
* @param {number} [width] - The width of the region to copy from the source image. If not specified it will use the full source image width.
971971
* @param {number} [height] - The height of the region to copy from the source image. If not specified it will use the full source image height.
972-
* @param {number} [tx] - The x coordinate to translate to before drawing. If not specified it will default to the `x` parameter.
973-
* @param {number} [ty] - The y coordinate to translate to before drawing. If not specified it will default to the `y` parameter.
972+
* @param {number} [tx] - The x coordinate to translate to before drawing. If not specified it will default to the `x` parameter. If `null` and `source` is a Display Object, it will default to `source.x`.
973+
* @param {number} [ty] - The y coordinate to translate to before drawing. If not specified it will default to the `y` parameter. If `null` and `source` is a Display Object, it will default to `source.y`.
974974
* @param {number} [newWidth] - The new width of the block being copied. If not specified it will default to the `width` parameter.
975975
* @param {number} [newHeight] - The new height of the block being copied. If not specified it will default to the `height` parameter.
976976
* @param {number} [rotate=0] - The angle in radians to rotate the block to before drawing. Rotation takes place around the center by default, but can be changed with the `anchor` parameters.
@@ -1000,6 +1000,9 @@ Phaser.BitmapData.prototype = {
10001000
this._alpha.current = source.alpha;
10011001
this._image = source.texture.baseTexture.source;
10021002

1003+
if (typeof tx === 'undefined' || tx === null) { tx = source.x; }
1004+
if (typeof ty === 'undefined' || ty === null) { ty = source.y; }
1005+
10031006
if (source.texture.trim)
10041007
{
10051008
// Offset the translation coordinates by the trim amount
@@ -1188,6 +1191,30 @@ Phaser.BitmapData.prototype = {
11881191

11891192
},
11901193

1194+
/**
1195+
* Draws the immediate children of a Phaser.Group to this BitmapData.
1196+
* Children are only drawn if they have their `exists` property set to `true`.
1197+
* 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.
1198+
* When drawing it will take into account the child's rotation, scale and alpha values.
1199+
* No iteration takes place. Groups nested inside other Groups will not be iterated through.
1200+
*
1201+
* @method Phaser.BitmapData#drawGroup
1202+
* @param {Phaser.Group} group - The Group to draw onto this BitmapData.
1203+
* @param {number} [blendMode=null] - The composite blend mode that will be used when drawing the Group children. The default is no blend mode at all.
1204+
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
1205+
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
1206+
*/
1207+
drawGroup: function (group, blendMode, roundPx) {
1208+
1209+
if (group.total > 0)
1210+
{
1211+
group.forEachExists(this.copy, this, null, null, null, null, null, null, null, null, null, null, null, null, null, null, blendMode, roundPx);
1212+
}
1213+
1214+
return this;
1215+
1216+
},
1217+
11911218
/**
11921219
* Sets the shadow properties of this BitmapDatas context which will affect all draw operations made to it.
11931220
* You can cancel an existing shadow by calling this method and passing no parameters.

0 commit comments

Comments
 (0)