Commit 9566ced2 authored by rockyl's avatar rockyl

修复包围盒计算的问题

parent a2a8ee9a
...@@ -439,41 +439,40 @@ export default class Container extends DisplayObject { ...@@ -439,41 +439,40 @@ export default class Container extends DisplayObject {
this._lastBoundsID = this._boundsID this._lastBoundsID = this._boundsID
this._bounds.clear(); this._bounds.clear();
//算自己的 //算自己的
this._calculateBounds(); if(!this._calculateBounds()){
for (let i = 0; i < this.children.length; i++) { for (let i = 0; i < this.children.length; i++) {
const child = this.children[i]; const child = this.children[i];
if (!child.visible || !child.renderable) { if (!child.visible || !child.renderable) {
continue; continue;
}
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
} }
if (child._bounds.height > child.$mask._bounds.height) { child.calculateBounds();
child._bounds.height = child.$mask._bounds.height; if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
} }
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
} }
} }
} }
/** /**
* 加"_"的方法基本是为了自己特殊处理 * 加"_"的方法基本是为了自己特殊处理
*/ */
protected _calculateBounds() { protected _calculateBounds(): boolean {
//子类自己重写 //子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y); //let wp = this.worldMatrix.transformPoint(this.x, this.y);
...@@ -496,7 +495,10 @@ export default class Container extends DisplayObject { ...@@ -496,7 +495,10 @@ export default class Container extends DisplayObject {
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3); matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4); matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4); Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
return true;
} }
return false;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment