Question

i need to add 5 continous backgroundimage as parallax scrolling node. so it will look like scrolling background..:;qst

my init code :-

//initialise paralllax
_backgroundNode = CCParallaxNodeExtras::node();
this->addChild(_backgroundNode, 1);
//create sprites
_fogA = CCSprite::create("bg1.png");
_fogB = CCSprite::create("bg2.png");
_liany = CCSprite::create("bg3.png");
_pnie = CCSprite::create("bg4.png");
_pniw = CCSprite::create("bg5.png");
//ratio
CCPoint bgSpeed = ccp(0.05, 0.05);
// add spriet to parallax node
_backgroundNode->addChild(_fogA, 0, bgSpeed, ccp(_fogA->getContentSize().width/2,_fogA->getContentSize().height/2));
_backgroundNode->addChild(_fogB, 0, bgSpeed, ccp(_fogA->getContentSize().width, _fogB->getContentSize().height/2));
_backgroundNode->addChild(_liany, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width), _liany->getContentSize().height/2));
_backgroundNode->addChild(_pnie, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width+_liany->getContentSize().width), _pnie->getContentSize().height/2));
_backgroundNode->addChild(_pniw, 0, bgSpeed, ccp((_fogA->getContentSize().width+_fogB->getContentSize().width+_liany->getContentSize().width+_pnie->getContentSize().width),_pniw->getContentSize().height/2));

my update method:-

//update method
void Game::processBackground(float dt)
{
// scroll 30 pixels backward in update
CCPoint backgroundScrollVert = ccp(-3000, 0);
_backgroundNode->setPosition(ccpAdd(_backgroundNode->getPosition(), ccpMult(backgroundScrollVert, dt)));
//create array objects to reset the image
CCArray * fogs = CCArray::createWithCapacity(5);
fogs->addObject(_fogA);
fogs->addObject(_fogB);
fogs->addObject(_liany);
fogs->addObject(_pnie);
fogs->addObject(_pniw);
for (int ii = 0; ii < fogs->count(); ii++)
{
CCSprite * fog = (CCSprite *)(fogs->objectAtIndex(ii));
float xPosition = _backgroundNode->convertToWorldSpace(fog->getPosition()).x - (fog->getContentSize().width/2);
float size = fog->getContentSize().width;
if (xPosition < -size)
{
_backgroundNode->incrementOffset(ccp(fog->getContentSize().width*2,0),fog);
}
}
}

somewhat all the 5 images coming, but in between images some black space are there.

am not undertsand why its coming ?

Was it helpful?

Solution

i came up with answer.... its working in coocs2d-x 2.2.2

here is link:- https://github.com/seenu19/CCParallaxScrollNode

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top