Skip to main content
1 of 6

Create an infinite scroll using CCParallaxNode in Cocos2D-X

Cocos2d-X! C++! Win/And/iOS!

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.

EDIT: I was using a scaled image for the sprite, with 512 width, scaled times 5.