c++ - Cocos2dx : How to stop CCFollow moving the ParallaxNode and making background black -


i trying follow herosprite using ccfollow, there 2 erratic behaviors happening .

i making camera follow sprite follows :

startsprite = ccsprite::createwithspriteframename("santa_001.png"); startsprite->setposition(ccp (size.width / 5 , size.height / 2 )); this->addchild(startsprite,1); this->runaction(ccfollow::create(herosprite, ccrectmake(0, 0, size.width, size.height * 2)));

now, happens :

a) background parallax node consisting of different sprites , moving @ different speed moving in "upward" direction when herosprite jumps upward. want keep sprites @ original position , not move upward herosprite. how do ?

voidnode = ccparallaxnodeextras::node();

voidnode->addchild(pspritegrass, 2, ccp(3.0f,0), ccp(0, size.height/10 - 50) );
voidnode->addchild(pspritegrass02, 3, ccp(3.0f,0), ccp(size.width - 10 , size.height/10 - 50) ); voidnode->addchild(psprite, 1, ccp(1.0f,0), ccp(0, size.height/10 - 50) ); voidnode->addchild(psprite02, 0, ccp(1.0f,0), ccp(size.width - 10, size.height/10 - 50) );

voidnode->addchild(pspritesky02, 0, ccp(0.6f,0), ccp(0, size.height /2 + 75) ); voidnode->addchild(pspritesky, 1, ccp(0.6f,0), ccp(size.width, size.height /2 + 75) );

voidnode->addchild(pspritestars, 2, ccp(2.0f,0), ccp(0, size.height - 110) ); voidnode->addchild(pspritestars02, 3, ccp(2.0f,0), ccp(size.width - 10, size.height - 110) );

voidnode->addchild(pspriteclouds, 4, ccp(1.2f,0), ccp(0, size.height - 110) ); voidnode->addchild(pspriteclouds02, 5, ccp(1.2f,0), ccp(size.width - 10, size.height - 110) );

ccactioninterval* go = ccmoveby::create(25, ccp(-1000,0) ); ccsequence* seq = ccsequence::create(go, null); voidnode->runaction( (ccrepeatforever::create(seq) ));

this->addchild( voidnode, 0 ); 

b) when hero moves upward, screen initialized white color turns black sometime when herosprite jumping. when comes down screen becomes white again. how make upward portion of screen white ?

cc_break_if(! cclayercolor::initwithcolor( ccc4(255,255,255,255) ) );

any suggestions or pointers helpful . thanks


update part b :

through "smugbit studios" suggestion, changed

initwithcolor:ccc4(255,255,255,255);

to

initwithcolor(ccc4(255, 255, 255, 255), size.width, size.height * 2);

and solves problem . still looking solve answer part .

for a, set bounds of ccfollow whatever want max height - in case, believe size.height, so:

this->runaction(ccfollow::create(herosprite, ccrectmake(0, 0, size.width, size.height))); 

for b, suspect main init of "this" cclayer, , not cclayercolor. change subclassing cclayercolor, , change new init to:

initwithcolor:ccc4(255,255,255,255) 

edit: correction answer b - need define layer size. if not defined, set screen size, appear trying go beyond height of screen. in case, use:

initwithcolor(ccc4(255, 255, 255, 255), width, height) 

where height maximum height display - (size.height*2).


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -