简体   繁体   中英

Sprite-kit: removeFromParent when parent gone

Is it safe to call [n removeFromParent]; after the parent to n has been released (and thus does not exist)?

I guess n.parent will be nil at that point.

Do I have to do something like

if (n.parent != nil)
  [n removeFromParent]; 

For reference:

https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/#//apple_ref/occ/instm/SKNode/removeFromParent

Yes, I do it all the time. If you want to validate, simply do something like this the next time you call want to do it.

[n removeFromParent];
[n removeFromParent];
[n removeFromParent];
[n removeFromParent];

You'll notice no side effects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM