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 cclayer
s). 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
Post a Comment