mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +00:00
BitmapData.drawFull draws the given Game Object or Group to a BitmapData and then recursively iterates through all of its children, including children of Game Objects and Groups. It can draw Text, BitmapText, Sprites, Images, Emitters and Graphics objects. It's perfectly valid to pass in game.world
as the parent object, and it will iterate through the entire display list.
This commit is contained in:
parent
176289f514
commit
103c37cd42
3 changed files with 121 additions and 54 deletions
15
README.md
15
README.md
|
@ -67,7 +67,19 @@ Rich - [@photonstorm](https://twitter.com/photonstorm)
|
|||
|
||||
![patreon](http://www.phaser.io/images/patreon.png)
|
||||
|
||||
Please help support the future development of Phaser through our [Patreon campaign](https://www.patreon.com/photonstorm). We've some exciting plans and there's so much we'd like to do - let's see if we can all work together to make this possible.
|
||||
Please help support the future development of Phaser through our [Patreon campaign](https://www.patreon.com/photonstorm). We've some exciting plans and there's so much we'd like to do. Let's see if we can all work together to make this possible.
|
||||
|
||||
### Phaser Sponsors
|
||||
|
||||
Phaser is [sponsored](https://www.patreon.com/photonstorm) by the following great companies:
|
||||
|
||||
![qici](http://www.phaser.io/images/sponsors/qici-100.png)
|
||||
|
||||
QICI Engine: [A powerful one-stop integrated Phaser game editor](http://www.qiciengine.com/)
|
||||
|
||||
![zenva](http://www.phaser.io/images/sponsors/zenva-100.png)
|
||||
|
||||
Zenva Academy: [Online courses on Phaser, HTML5 and native app development](https://academy.zenva.com/?zva_src=phaserpatreon)
|
||||
|
||||
<a name="download"></a>
|
||||
## Download Phaser
|
||||
|
@ -261,6 +273,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
|
|||
* Line.centerOn will position the Line so that its midpoint lays on the coordinates given.
|
||||
* BitmapData.line draws a line to the BitmapData in the color and thickness specified.
|
||||
* BitmapData.op is a handy short-code to get and set the canvas global composite operator.
|
||||
* BitmapData.drawFull draws the given Game Object or Group to a BitmapData and then recursively iterates through all of its children, including children of Game Objects and Groups. It can draw Text, BitmapText, Sprites, Images, Emitters and Graphics objects. It's perfectly valid to pass in `game.world` as the parent object, and it will iterate through the entire display list.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -1184,7 +1184,7 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
this._image = source;
|
||||
|
||||
if (source instanceof Phaser.Sprite || source instanceof Phaser.Image || source instanceof Phaser.Text)
|
||||
if (source instanceof Phaser.Sprite || source instanceof Phaser.Image || source instanceof Phaser.Text || source instanceof PIXI.Sprite)
|
||||
{
|
||||
// Copy over sprite values
|
||||
this._pos.set(source.texture.crop.x, source.texture.crop.y);
|
||||
|
@ -1412,6 +1412,59 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Draws the Game Object or Group to this BitmapData and then recursively iterates through all of its children.
|
||||
*
|
||||
* If a child has an `exists` property then it (and its children) will be only be drawn if exists is `true`.
|
||||
*
|
||||
* 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. You should resize the BitmapData in advance to match the overall bounds of the top-level Game Object.
|
||||
*
|
||||
* When drawing it will take into account the child's world rotation, scale and alpha values.
|
||||
*
|
||||
* It's perfectly valid to pass in `game.world` as the parent object, and it will iterate through the entire display list.
|
||||
*
|
||||
* @method Phaser.BitmapData#drawFull
|
||||
* @param {Phaser.World|Phaser.Group|Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText} parent - The Game Object to draw onto this BitmapData and then recursively draw all of its children.
|
||||
* @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'.
|
||||
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
drawFull: function (parent, blendMode, roundPx) {
|
||||
|
||||
if (parent.worldVisible === false || parent.worldAlpha === 0 || (parent.hasOwnProperty('exists') && parent.exists === false))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
if (parent.type !== Phaser.GROUP && parent.type !== Phaser.EMITTER && parent.type !== Phaser.BITMAPTEXT)
|
||||
{
|
||||
if (parent.type === Phaser.GRAPHICS)
|
||||
{
|
||||
var bounds = parent.getBounds();
|
||||
this.ctx.save();
|
||||
this.ctx.translate(bounds.x, bounds.y);
|
||||
PIXI.CanvasGraphics.renderGraphics(parent, this.ctx);
|
||||
this.ctx.restore();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.copy(parent, null, null, null, null, parent.worldPosition.x, parent.worldPosition.y, null, null, parent.worldRotation, null, null, parent.worldScale.x, parent.worldScale.y, parent.worldAlpha, blendMode, roundPx);
|
||||
}
|
||||
}
|
||||
|
||||
if (parent.children)
|
||||
{
|
||||
for (var i = 0; i < parent.children.length; i++)
|
||||
{
|
||||
this.drawFull(parent.children[i], blendMode, roundPx);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the shadow properties of this BitmapDatas context which will affect all draw operations made to it.
|
||||
* You can cancel an existing shadow by calling this method and passing no parameters.
|
||||
|
|
|
@ -653,7 +653,7 @@ PIXI.Graphics.prototype.generateTexture = function(resolution, scaleMode)
|
|||
|
||||
canvasBuffer.context.scale(resolution, resolution);
|
||||
|
||||
canvasBuffer.context.translate(-bounds.x,-bounds.y);
|
||||
canvasBuffer.context.translate(-bounds.x, -bounds.y);
|
||||
|
||||
PIXI.CanvasGraphics.renderGraphics(this, canvasBuffer.context);
|
||||
|
||||
|
@ -823,84 +823,84 @@ PIXI.Graphics.prototype._renderCanvas = function(renderSession)
|
|||
*/
|
||||
PIXI.Graphics.prototype.getBounds = function(matrix)
|
||||
{
|
||||
if(!this._currentBounds)
|
||||
if (!this._currentBounds)
|
||||
{
|
||||
|
||||
// return an empty object if the item is a mask!
|
||||
// Return an empty object if the item is a mask!
|
||||
if (!this.renderable)
|
||||
{
|
||||
return PIXI.EmptyRectangle;
|
||||
}
|
||||
|
||||
if (this.dirty)
|
||||
{
|
||||
this.updateLocalBounds();
|
||||
this.webGLDirty = true;
|
||||
this.cachedSpriteDirty = true;
|
||||
this.dirty = false;
|
||||
}
|
||||
if (this.dirty)
|
||||
{
|
||||
this.updateLocalBounds();
|
||||
this.webGLDirty = true;
|
||||
this.cachedSpriteDirty = true;
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
var bounds = this._localBounds;
|
||||
var bounds = this._localBounds;
|
||||
|
||||
var w0 = bounds.x;
|
||||
var w1 = bounds.width + bounds.x;
|
||||
var w0 = bounds.x;
|
||||
var w1 = bounds.width + bounds.x;
|
||||
|
||||
var h0 = bounds.y;
|
||||
var h1 = bounds.height + bounds.y;
|
||||
var h0 = bounds.y;
|
||||
var h1 = bounds.height + bounds.y;
|
||||
|
||||
var worldTransform = matrix || this.worldTransform;
|
||||
var worldTransform = matrix || this.worldTransform;
|
||||
|
||||
var a = worldTransform.a;
|
||||
var b = worldTransform.b;
|
||||
var c = worldTransform.c;
|
||||
var d = worldTransform.d;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
var a = worldTransform.a;
|
||||
var b = worldTransform.b;
|
||||
var c = worldTransform.c;
|
||||
var d = worldTransform.d;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
|
||||
var x1 = a * w1 + c * h1 + tx;
|
||||
var y1 = d * h1 + b * w1 + ty;
|
||||
var x1 = a * w1 + c * h1 + tx;
|
||||
var y1 = d * h1 + b * w1 + ty;
|
||||
|
||||
var x2 = a * w0 + c * h1 + tx;
|
||||
var y2 = d * h1 + b * w0 + ty;
|
||||
var x2 = a * w0 + c * h1 + tx;
|
||||
var y2 = d * h1 + b * w0 + ty;
|
||||
|
||||
var x3 = a * w0 + c * h0 + tx;
|
||||
var y3 = d * h0 + b * w0 + ty;
|
||||
var x3 = a * w0 + c * h0 + tx;
|
||||
var y3 = d * h0 + b * w0 + ty;
|
||||
|
||||
var x4 = a * w1 + c * h0 + tx;
|
||||
var y4 = d * h0 + b * w1 + ty;
|
||||
var x4 = a * w1 + c * h0 + tx;
|
||||
var y4 = d * h0 + b * w1 + ty;
|
||||
|
||||
var maxX = x1;
|
||||
var maxY = y1;
|
||||
var maxX = x1;
|
||||
var maxY = y1;
|
||||
|
||||
var minX = x1;
|
||||
var minY = y1;
|
||||
var minX = x1;
|
||||
var minY = y1;
|
||||
|
||||
minX = x2 < minX ? x2 : minX;
|
||||
minX = x3 < minX ? x3 : minX;
|
||||
minX = x4 < minX ? x4 : minX;
|
||||
minX = x2 < minX ? x2 : minX;
|
||||
minX = x3 < minX ? x3 : minX;
|
||||
minX = x4 < minX ? x4 : minX;
|
||||
|
||||
minY = y2 < minY ? y2 : minY;
|
||||
minY = y3 < minY ? y3 : minY;
|
||||
minY = y4 < minY ? y4 : minY;
|
||||
minY = y2 < minY ? y2 : minY;
|
||||
minY = y3 < minY ? y3 : minY;
|
||||
minY = y4 < minY ? y4 : minY;
|
||||
|
||||
maxX = x2 > maxX ? x2 : maxX;
|
||||
maxX = x3 > maxX ? x3 : maxX;
|
||||
maxX = x4 > maxX ? x4 : maxX;
|
||||
maxX = x2 > maxX ? x2 : maxX;
|
||||
maxX = x3 > maxX ? x3 : maxX;
|
||||
maxX = x4 > maxX ? x4 : maxX;
|
||||
|
||||
maxY = y2 > maxY ? y2 : maxY;
|
||||
maxY = y3 > maxY ? y3 : maxY;
|
||||
maxY = y4 > maxY ? y4 : maxY;
|
||||
maxY = y2 > maxY ? y2 : maxY;
|
||||
maxY = y3 > maxY ? y3 : maxY;
|
||||
maxY = y4 > maxY ? y4 : maxY;
|
||||
|
||||
this._bounds.x = minX;
|
||||
this._bounds.width = maxX - minX;
|
||||
this._bounds.x = minX;
|
||||
this._bounds.width = maxX - minX;
|
||||
|
||||
this._bounds.y = minY;
|
||||
this._bounds.height = maxY - minY;
|
||||
this._bounds.y = minY;
|
||||
this._bounds.height = maxY - minY;
|
||||
|
||||
this._currentBounds = this._bounds;
|
||||
}
|
||||
|
||||
return this._currentBounds;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -927,7 +927,7 @@ PIXI.Graphics.prototype.containsPoint = function( point )
|
|||
// only deal with fills..
|
||||
if (data.shape)
|
||||
{
|
||||
if ( data.shape.contains( tempPoint.x, tempPoint.y ) )
|
||||
if (data.shape.contains(tempPoint.x, tempPoint.y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -935,6 +935,7 @@ PIXI.Graphics.prototype.containsPoint = function( point )
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue