Cocos2d: how to create a continuous parallax layer

I create a game in cocos 2d,

I want to create a parallax layer that has continuous scrolling. For example, my script:


A pair of clouds moving in the background. Once it reaches the end of the right screen, it should appear again on the left side of the screen. Or some kind of effect, like endless parallax. Any ideas please?


+4
source share
2 answers

You really don't need to create a parallax node for this,

create a cloud sprite:

CCSprite *blackCloud;//set it image and position it: //code for init blackCloud.position = ccp(580,300); //call selector (don't unscheduled it) [self schedule:@selector(blackCloudMovement) interval:1/30]; -(void)blackCloudMovement { if (blackCloud.position.x == -100) { [blackCloud setPosition:ccp(580,300)]; [blackCloud runAction:[CCMoveTo actionWithDuration:6 position:ccp(-100,300)]]; } } 
+1
source

You can achieve parallax in a 2D game by moving layers at a multiple of the speed at which you move your camera or protagonist according to their "depth"; for example, when a player moves 1 unit of distance, a layer at depth 1 moves 0.5, a layer at depth 2 moves 0.25, a layer at depth 3 moves 0.125, etc.

0
source

All Articles