diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index bb972f4..1d54df9 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -214,43 +214,22 @@ */ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) { - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; + var index1 = this.children.indexOf(child); + var index2 = this.children.indexOf(child2); + + this.removeChild(child); + this.removeChild(child2); - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) + if(index1 < index2) { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - + this.addChildAt(child2, index1); + this.addChildAt(child, index2); } else { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ + this.addChildAt(child, index2); + this.addChildAt(child2, index1); + } } /**