diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 9e2e85e..a303599 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -196,27 +196,42 @@ /** * Removes a child from the container. * - * @param {...PIXI.DisplayObject} childs - The DisplayObject(s) to remove + * @param {...PIXI.DisplayObject} child - The DisplayObject(s) to remove * @return {PIXI.DisplayObject} The first child that was removed. */ - removeChild(...childs) + removeChild(child) { - for (let i = 0; i < childs.length; ++i) + const argumentsLength = arguments.length; + + // if there is only one argument we can bypass looping through the them + if (argumentsLength > 1) { - const child = childs[i]; + // loop through the arguments property and add all children + // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes + for (let i = 0; i < argumentsLength; i++) + { + this.removeChild(arguments[i]); + } + } + else + { const index = this.children.indexOf(child); - if (index === -1) continue; + if (index === -1) return null; child.parent = null; removeItems(this.children, index, 1); + // ensure a transform will be recalculated.. + this.transform._parentID = -1; + this._boundsID++; + // TODO - lets either do all callbacks or all events.. not both! this.onChildrenChange(index); child.emit('removed', this); } - return childs[0]; + return child; } /**