Reputation: 9742
If I have a CCSprite that has previously been added to a parent CCNode or CCLayer, is there any way to change its parent object?
I tried doing:
[self setParent:newParent];
...
and then:
[parent removeChild:self cleanup:YES];
[newParent addChild:self];
Neither works... THe latter actually causes a crash.
Upvotes: 0
Views: 235
Reputation: 10860
I assume that in the second case you added autoreleased object to the parent. In this case sprite will be deleted after removing from parent, so you will not be able to add it to another parent. Try this
[self retain];
[self removeFromParentWithCleanup:YES];
[newParent addChild: self];
[self release];
And in the case of crash with error, post the crash message in future. It can help to figure out problem.
Upvotes: 1
Reputation: 9079
I think if you first remove (NO cleanup), then add to new parent, it should work.
Upvotes: 0