Merge pull request #431 from namuol/swapChildren
`swapChildren` implementation
This commit is contained in:
commit
05ca70e128
1 changed files with 18 additions and 31 deletions
|
@ -214,43 +214,30 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
|||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
|
||||
{
|
||||
/*
|
||||
* this funtion needs to be recoded..
|
||||
* can be done a lot faster..
|
||||
*/
|
||||
return;
|
||||
if(child === child2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index1 = this.children.indexOf(child);
|
||||
var index2 = this.children.indexOf(child2);
|
||||
|
||||
// need to fix this function :/
|
||||
/*
|
||||
// TODO I already know this??
|
||||
var index = this.children.indexOf( child );
|
||||
var index2 = this.children.indexOf( child2 );
|
||||
if(index1 < 0 || index2 < 0) {
|
||||
throw new Error("swapChildren: Both the supplied DisplayObjects must be a child of the caller.");
|
||||
}
|
||||
|
||||
this.removeChild(child);
|
||||
this.removeChild(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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue