Cocos2d-x Parallax Infinite Scrolling Error

Good day,

I am writing a code that will infinitely scroll that is parallax, but I can’t seem to do this correctly.

here is my code:

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();


auto mountainSprite = Sprite::create( "Mountain.png" );
auto treesSprite = Sprite::create( "Trees.png" );
auto housesSprite = Sprite::create( "Houses.png" );

auto paraNode = ParallaxNode::create();
paraNode->addChild(mountainSprite, -1, Vec2(0.4f,0.5f), Vec2(800,480));

paraNode->addChild(treesSprite, 1, Vec2(2.2f,1.0f), Vec2(800,480));

paraNode->addChild(housesSprite, 2, Vec2(3.0f,2.5f), Vec2(800,480));

The result is a black blank screen.

Also, I have this follow-up questions:

  1. Can I replace the “Vec2(float xx, float yy)” with “Point(x,y)” here? Because it seems not of cocos2d-x version 3.6? what is “ccp(x,y)”? which is better Vec2, Point or ccp?

  2. What is “positionOffset” that this “addChild (Node *child, int z, const Vec2 &parallaxRatio, const Vec2 &positionOffset)”, talks about? from link: ParallaxNode Class Reference

  3. I tried this tutorial: Raywenderlich Parallax Tutorial, but don’t understand it, can someone explain it to me? The things that confused me is what are those “CCSprite” is this the same as “Sprite”, why?, “CCParallaxNode” is this the same as “ParallaxNode”, why?

and what is “[self addChild:_backgroundNode z:-1]” is this the
same as “this->addChild(node)”?

Any answer or suggestion to any questions are appreciated. Thanks :smiley:

We also have this: http://cocos2d-x.org/programmersguide/7/ scroll down to the bottom for Parallax Node.