cocos2d x - Cocos2dx sublayers -


i developing 2d games cocos2dx, in still new... inside game, there's number of ui elements i'd group 1 (i intend group them cclayers). example few text labels , sprites form cstatbar cclayer. cstatbar included in various other cclayer

how do that? created cstatbar class , then, inside containing class's init() function, cstatbar::create() , call this->addchild(pstatbar) however, statbar did not appear... there obvious thing missed? positions correct. thanks!

edit:

notes: 1. cctouchesbegan of sublayer called, not rendered/seen 2. how resize sublayer cover partial area of parent layer? supposedly cstatbar should cover 10% of top area of screen, not whole screen...

inside cparent::init() function, can initialize csublayer so:

        // create , initialize csublayer     csublayer* psublayer= csublayer::create();     float fwidth = psublayer->getcontentsize().width;     float fheight = psublayer->getcontentsize().height;     psublayer->setposition(ccp(fwidth/2.0f, fheight/2.0f));     this->addchild( psublayer ); 

and csublayer can defined other cclayer.

if want restrict csublayer smaller cparent layer, can inside init function so:

csublayer::init() {         // initialize size size of background sprite     ccsprite *pspritebackground = ccsprite::createwithspriteframe(         ccspriteframecache::sharedspriteframecache()->spriteframebyname("background.png")     );     this->setcontentsize(ccsize(pspritebackground->getcontentsize().width, pspritebackground->getcontentsize().height));     pspritebackground->setposition(ccp(fscreenhalfwidth, fscreenheight-(pspritebackground->getcontentsize().height/2.0f)));     this->addchild(pspritebackground); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -