Game Development Reference
In-Depth Information
Working with Nodes
The CCNode class implements all the methods to add, get, and remove child nodes.
Here are some of the ways you can work with child nodes:
▪ You can create a new node:
CCNode* childNode = [CCNode node];
▪ You can add the new node as a child:
[myNode addChild:childNode z:0 tag:123];
▪ You can retrieve the child node:
▪ You can remove the child node by tag; cleanup will also stop any run-
ning actions:
[myNode removeChildByTag:123 cleanup:YES];
▪ You can remove the node if you have a pointer to it:
[myNode removeChild:retrievedNode];
▪ You can remove every child of the node:
[myNode removeAllChildrenWithCleanup:YES];
▪ You can remove myNode from its parent:
[myNode removeFromParentAndCleanup:YES];
The z parameter in addChild determines the draw order of the node. The node with
the lowest z value is drawn first; the one with the highest z value is drawn last. If mul-
tiple nodes have the same z value, they're simply drawn in the order they were added.
Of course, this applies only to nodes that have a visual representation, such as sprites.
The tag parameter lets you identify and obtain specific nodes at a later time using the
getChildByTag method.
Search Nedrilad ::

Custom Search