I am trying to follow my heroSprite using CCFollow, but there are two erratic behaviors that are happening .
I am making the camera follow my sprite as 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, what happens is :
a) The background Parallax Node consisting of different sprites and moving at different speed are also moving in "upward" direction when the heroSprite jumps upward. I want to keep this sprites at their original position and not move upward with the heroSprite. How do I do that ?
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 the hero moves upward, the screen which is initialized with white color turns black for sometime when the heroSprite is jumping. When it comes down the screen becomes white again. How do I make the upward portion of the screen white as well ?
CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );
Any suggestions or pointers would be helpful . Thanks
UPDATE FOR PART B :
Through "Smugbit Studios" suggestion, I changed
initWithColor:ccc4(255,255,255,255);
to
initWithColor(ccc4(255, 255, 255, 255), size.width, size.height * 2);
and it solves my problem . I am still looking to solve answer part a .