I have an SKScene with a node (big square) in the center. I have other nodes on it and I would like to change the parent of those to mySquare instead of the scene.
I tried using myNode.moveToParent(mySquare). It seems to work as I can find my nodes under mySquare in the node tree (for node in mySquare.children print me the right nodes). My problem is that I do not see those nodes anymore...
I was wondering if the node could have the wrong position so I tried changing it's position with node.position = mySquare.convertPoint(node.position, fromNode: self). I tried putting the node's position in a temporary variable before the moveToParent and convert this position instead, it did not work. I then tried to simply position the node at the center of mySquare with node.position = CGPoint(x: 0.5, y: 0.5) which is the anchor point of mySquare but the node still disappeared.
I tested the position by putting an SKEmitter on the node with sparks. The sparks are exactly where the node was when it's parent was the Scene, which means, at the right position. But the node is not there.
Would you have any idea on how to fix this?
Thank you very much for your time.
Additionnal informations
This is how I created my node
let object = SKSpriteNode(imageNamed: "myObject")
self.addChild(copy() as! SKSpriteNote)
I set the position to match the touch (I create when I touch inside mySquare).
mySquare is already in the scene from the beginning (I dragged an SKShapeNode in the scene editor which is a square).
This is where I change the parent
func sizeOfObject(sender: UIPinchGestureRecognizer){
if (sender.state == .Began){
for nodes in nodesOnMySquare {
let pos = table.convertPoint(node.position, fromNode: self)
node.removeFromParent()
table.addChild(node)
node.position = pos
}
}
In my for loop I also tested moveToParent, like this
node.moveToParent(table) //Same result, the node disappear