I'm trying to create an infinite scroll using two images in a CCParallaxNode, making one move to the end of the scroll when it gets off the screen. I have tried several implementations but none has worked. The method setPosition is not available for the sprites once they have been added to the parallaxnode, and the array where the offset positions are stored is not documented so I don't know how to handle it.
Given that you cannot add the same child twice because the program crashes, I have tried to add a new sprite at the end whenever the old one dissappeared from screen. But the getPosition methods for either the sprites or the scroll doesn't seem to give accurate positions to calculate when a sprite is outside the screen. I ended up implementing a loop that added N sprites in a row and then "breaking" the program.
I was using a scaled image for the sprite with 512 width, scaled times 5. Screen size 1024x768
EDIT FOR CODE SNIPPET
init
voidNode = CCParallaxNode::node();
parta = CCSprite::spriteWithFile("backg.png");
parta->setScaleX( 5 );
parta->setAnchorPoint(ccp(0,0));
parta->setPosition(ccp(0,0));
voidNode->addChild(parta, -1, ccp(0.4f,0.5f), ccp(0,0));
maxscroll = parta->getContentSize().width*5;
CCMoveBy* moveRight = CCMoveBy::actionWithDuration(0.1f,ccp(-600, 0));
CCRepeatForever* repeat =
CCRepeatForever::actionWithAction((CCSequence *)CCSequence::actions(moveRight,0));
voidNode->runAction(repeat);
update
// I tried with voidNode->getPos() and voidNode->m_tLastPosition.x too
int newPos = parta->getPosition().x;
if (maxscroll - abs(newpositionbnewPos) - initpositionbinitPos) < level->getContentSize().width*5){
// 1st: parta->setPosition wont work, even when goten as child
// 2nd: I dont now how to access the m_pParallaxArray to alter the offset positions
// 3rd implementation
parta = CCSprite::spriteWithFile("backg.png");
parta->setScaleX( 5 );
parta->setAnchorPoint(ccp(0,0));
voidNode->addChild(parta, -1, ccp(0.4f,0.5f), ccp(maxscroll,0));
maxscroll += parta->getContentSize().width*5;
}