DzNode->setNodeParent protected
Alessandro Mastronardi
Posts: 2,619
Any chance to set a parent node without having to subclass DzNode, since setNodeParent is protected?
Comments
-Rob
Thanks Rob, I already tried addNodeChild and didn't work as expected: the children nodes were added to the main one, but would not render.
Then, I tried to add the child node to the scene, and after that call the addNodeChild. That worked.
I expected that actually addNodeChild, having that "add" word in it, would automatically add the child node to the scene as well. That misled me.
DzNode::addNodeChild() doesn't automatically add the node to the scene because you may want to do something to/with that node before it gets drawn. When the scene draws, only those nodes that have already been added to the scene are processed. In cases where there is creation and a parent/child relationship at play... we typically create the node, DzNode::addNodeChild(), do any work based on that relationship and then DzScene::addNode() once we are ready for that node to be displayed to the user. If the node is added to the scene too early, not only can it be a bit disconcerting to the user to see things they shouldn't, it can cause a significant performance hit because there are a number of connections that get made and you begin paying for the drawing.
-Rob
Thank you very much for the detailed explanation Rob, now that makes sense.