How can we add Parallax scrolling to Cocos 2D?

how can we add Parallax scrolling in Cocos 2D version 3 (IOS). I have studied many tutorials but nothing worked for me. I tried the following code but didn't work. can you list the steps to achieve Parallax scrolling in Cocos2D game. i am new to game development. your help will be much appreciated. thank

CCParallaxNode *voidNode = [CCParallaxNode node];
[voidNode addChild:bg4 z:1 parallaxRatio:ccp(3.5f, 3.5f) positionOffset:ccp(3.5f, 3.5f)];
[voidNode addChild:_spacedust1 z:2 parallaxRatio:ccp(3.5f, 3.5f) positionOffset:ccp(3.5, 3.5)];
[self addChild:voidNode]; 



source to share

1 answer

You just move voidNode

. All children you add to voidNode will be moved relative voidNode


So, for example, the foreground should be moved exactly like voidNode

, then you will create a parallaxRatio ccp(1.f, 1.f)


Then the background, for example, needs to be moved slower than the foreground, you do a parallaxRatio ccp(0.6f, 0.6f)




All Articles