I want to move a SKSpriteNode from one SKNode to another. The removeFromParent method actually deallocates the sprite.
For example in this code MySprite is a subclass of SKSpriteNode with a dealloc custom method that output a string, just to let me know that the object was deallocated:
SKNode *node1 = [SKNode node];
SKNode *node2 = [SKNode node];
//[self addChild:node1];
//[self addChild:node2];
MySprite *sprite = [MySprite spriteNodeWithColor:[SKColor blueColor] size:CGSizeMake(30, 30)];
[node1 addChild:sprite];
[sprite removeFromParent];
[node2 addChild:sprite];
In this case the sprite is deallocated. I thought that having a strong reference to sprite should keep it alive even after calling the removeFromParent, but it doesn't.
But if I uncommented [self addChild:node2]; The sprite was not deallocated.
I'm pretty confused here. If the removeFromParent deallocated the object, sprite should be nil and I should get an error for adding a nil node to parent. Isn't it? The documentation just say that removeFromParent: "Removes the receiving node from its parent." but it says nothing about how memory is managed here.