0
votes

In cocos2d-iPhone we have a CCNode which:

  • has a position
  • has a size (wether we like it or not, it has)
  • an anchor point

This is very useful to define areas on screen where that area has children that belong together. Like a group of buttons. We can easily hide/unhide everything just by hiding that parent CCNode.

What is the equivalent in cocos2d-x? I see that Node does not have a size. Layer seems like its going to be deprecated... and according to the docs, a Sprite is something that moves. Where is the logical stuff?

2
You can just use Node in cocos2d-x ( CC prefix for v2 ) and then override setVisible() function. (by iterating through Node's children and set their visibility recursively )Emadpres

2 Answers

0
votes

Implement that function by yourself:

void setVisibilityWithChildren(CCNode* parent, bool bVisible) {
    if (0 == parent) return;
    CCNode* node = NULL;
    CCARRAY_FOREACH(parent->getChildren(), node)
    {
        setVisibilityWithChildren(node, bVisible);
        if (node) node->setVisible(bVisible);
    }
}
0
votes

In cocos2d-x, CCNode has the same attributes as it in cocos2d. Including size, position, anchor point and so on.

I don't know what it like in cocos2d, but in cocos2d-x CCNode is something without graph. You may consider that it is invisible.

If you wish to see where and what the size it is. You may use CCLayerColor instead. All of the functions you use are the same as CCNode, besides an extra step setColor()

CCNode => CCLayer => CCLayerRGBA => CCLayerColor (this is the inheritance tree of CCLayerColor in cocos2d-x 2.2.6)