Moving objects inside a Paralax (a.k.a. infinite scroll)

Moving objects inside a Paralax (a.k.a. infinite scroll)
0.0 0


I’m trying to implement infinite scroll using parallaxnodes.

What I came up with (q&d) is to create 2 instances of the background, and as soon as one is outside of the screen, reposition it at the end of the other.

My ParallaxNode has both elements added, but when I try to use setPosition in any of them nothing happens. I also tried removing them from the childList, then re-adding them in a new position, but the program crashes as it breaks the rule of “not the same child node twice”.



I have done it by creating new sprites and adding them at the offset position, but as I want an unlimited amount I need some kind of control variable on when to add a new one. None of the getPosition() for either the parallaxnode or any of the nodes seems to give a sensible value and I cannot find a class member that stores the scroll position at any given time.


It seems that m_pParallaxArray (protected) at CCParallaxNode stores the offset of children.
I don’t find a member function for getting this variable.

One possible workaround without editing cocos2d-x is to use removeChild, and addChild with the new offset.

Looking for a better solution :slight_smile: