A question I see frequently asked by Cocos2D developers, in simplified form:
"I have this node A, how can I access this other node B?"
Whether it’s executing a message or getting the node itself as a reference, developers have a problem accessing nodes in other parts of the scene. Or the scene itself.
The most obvious is also a potentially dangerous solution: initialize the node with the references to the other nodes it needs. The danger lies in retain cycles, when node A has a retaining reference to node B and vice versa – then neither of them will let go, memory is leaked, strange bugs appear.
From the Cocos2D questions on stackoverflow.com it’s obvious how prevalent retain cycles issues are among Cocos2D developers. Therefore this article with strategies for accessing other nodes in various situations with their benefits and drawbacks.
And an explanation why self.parent.parent.parent… is really terrible practice.
Essential Cocos2D: Free Sample
Today’s iDevBlogADay article is a sample article from the upcoming Essential Cocos2D online documentation. That’s why it’s on a separate page.
More about Essential Cocos2D soon. It’s growing fast. And not to forget: Learn cocos2d 2 is now available!
|Follow @gaminghorror||Follow @kobold2d|