Altering Scene Graphs
73
Altering Scene Graphs
After using csGroup::addChild() to create a scene graph, you can use the following
methods to edit it:
void removeChild(int i);
int removeChild(csNode *node);
int replaceChild(csNode *old, csNode *node);
void insertChild(int i, csNode *node);
These methods allow you to remove, replace, or insert a child node, respectively. For
example, to insert a node between two children, use the insertChild() method:
csShape *myShape = new csShape;
root->insertChild(2, myShape);
The children nodes are numbered starting with 0. The “2” in the argument of
insertChild() specifies that the myShape node should be inserted in the scene graph as
the number two node.
Note: Although leaf nodes attached to the same group node can be acted upon in any
order, the first node added to a group node is always node zero, the second node added
to the root node in the code is node one, and so forth.
csGroup also supplies the following methods for finding the number of a node in a scene
graph, returning the number of children in a scene graph, and setting the number of
nodes in a group, respectively.
int searchChild(csNode *node);
int getChildCount();
void setChildCount(int count);
In general, you use the searchChild() method to return the number of a node so you can
perform other functions on or around it, such as replacing it.