I'm trying to implement a simple "move to back" / "move to front" without relying on the heavy lifting of something like https://github.com/pixijs/pixi-display
Here's my ordering code, but it doesn't seem to always work... though it does work some of the time... I think it looks like for some of the items it works but in reverse? What am I missing?
//moves an item in an array to either the front or back
export const PopTo = (isFront:boolean) => items => item => {
const copy = items.concat();
const ret = copy.splice(copy.indexOf(item), 1);
return (isFront) ? ret.concat(copy) : copy.concat(ret);
}
export const PopToFront = PopTo(true);
export const PopToBack = PopTo(false);
//move item to back
this.children = PopToBack (this.children) (target)
//move item to front
this.children = PopToFront (this.children) (target)