Game Development Reference
In-Depth Information
for CCScene , which is also just an abstract concept in order to enforce a common root
node class. Otherwise a CCScene class is virtually the same as a CCNode .
Caution The nodes in a cocos2d node hierarchy are positioned relative to their
parent nodes. The child nodes inherit certain properties from their parents, such
as scale and rotation but not color and opacity . This may be confus-
ing the first time you experience it.
For example, if the parent of a CCLabelTTF node is a nondrawing node—like
the CCNode , CCScene , or CCLayer nodes—and they themselves are the
only children of other nondrawing nodes, the position of the label will be relat-
ive to the view's lower left-hand corner. So, all is well and as expected. But if
you add another CCLabelTTF as a child to this label, the position of the child
label will be relative to the parent label.
You would have reason to expect the child label to be centered on the parent
label's position. Alas, this is not the case, as you can see in Figure 3-4 . You'll
find that the child label will be centered on the lower left-hand corner of
the parent label's texture instead, which is an unfortunate oddity in cocos2d's
design. To correctly position such a node and center it on its parent node, you
have to use parent node's contentSize.width / 2 and contentS-
ize.height / 2 as the child node's position.x and position.y .
Figure 3-4 . Caution: the default position of a child node is unexpectedly offset from its parent's position
 
 
Search Nedrilad ::




Custom Search