I have a ton of identical SKSpriteNodes added to my scene, all with the same zPosition, layered on top of each other according to the order they are added to the scene. I need to be able to pick one SKSpriteNode, and add another at the same index (plus or minus one). I know I can use scene.insertChild(mySpriteNode, atIndex:index)
but how do I get that index from a SKNode or SKSpriteNode? I have looked through the documentation, and online, there must be something I am missing, it seems like it would be so simple! My ideal solution:
scene.insertChild(mySpriteNode, atIndex:someSpriteNode.siblingIndex)
but I do not see a property on SKNode like siblingIndex, or maybe it would be called indexInParent.
I suppose I could keep count of every node I add to the scene, and subclass SKSpriteNode and set my own index, but I add nodes in a couple different places. This would be tedious and easily broken if I try and change my code later.
Maybe I could iterate through the entire children array property on the scene until I found the node === the node I am searching for, but this is very expensive and inefficient.
And using the zPosition is not ideal because I am using zPosition for a few other layers in the app, and the amount of SKSpriteNodes that can be added is unlimited, so eventually I would break through to the next layer.
Hopefully someone tells me I have simply overlooked this property somewhere! Any help is appreciated thanks!