fixed getBoundingBoxToWorld

This commit is contained in:
2youyouo2
2016-02-25 13:47:48 +08:00
parent 116dc133ef
commit a2c4ed7891
+49 -2
View File
@@ -1258,12 +1258,59 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
},
/**
* Returns a "world" axis aligned bounding box of the node.
* Returns a "world" axis aligned bounding box of the node.<br/>
* The bounding box contains self and active children's world bounding box.
* @method getBoundingBoxToWorld
* @return {Rect}
*/
getBoundingBoxToWorld: function () {
return this._sgNode.getBoundingBoxToWorld();
var size = this.getContentSize();
var width = size.width;
var height = size.height;
var rect = cc.rect(-this.anchorX * width, -this.anchorY * height, width, height);
var trans = this.getNodeToWorldTransform();
cc._rectApplyAffineTransformIn(rect, trans);
//query child's BoundingBox
if (!this._children)
return rect;
var locChildren = this._children;
for (var i = 0; i < locChildren.length; i++) {
var child = locChildren[i];
if (child && child.active) {
var childRect = child._getBoundingBoxTo(trans);
if (childRect)
rect = cc.rectUnion(rect, childRect);
}
}
return rect;
},
_getBoundingBoxTo: function (parentTransform) {
var size = this.getContentSize();
var width = size.width;
var height = size.height;
var rect = cc.rect(-this.anchorX * width, -this.anchorY * height, width, height);
var trans = (parentTransform === undefined) ? this.getNodeToParentTransform() : cc.affineTransformConcat(this.getNodeToParentTransform(), parentTransform);
cc._rectApplyAffineTransformIn(rect, trans);
//query child's BoundingBox
if (!this._children)
return rect;
var locChildren = this._children;
for (var i = 0; i < locChildren.length; i++) {
var child = locChildren[i];
if (child && child.active) {
var childRect = child._getBoundingBoxTo(trans);
if (childRect)
rect = cc.rectUnion(rect, childRect);
}
}
return rect;
},
/**