vishnu
vishnu

Reputation: 879

cocos2d:how to create continous parallax layer

I am creating an game in cocos 2d ,

I want to make a parallax layer that is having continuous scrolling. For example my scenario is:


Couple of clouds moving in back ground. As soon as it reaches the end of right screen, it should come again from left side of screen. Or some effect like never ending parallax. Any ideas please?


Upvotes: 4

Views: 891

Answers (2)

Nicolas Miari
Nicolas Miari

Reputation: 16246

You can achieve parallax in a 2D game by moving the layers at a multiple of the speed you move your camera or main character, according to their 'depth'; e.g. When player moves 1 unit of distance, layer at depth 1 moves by 0.5, layer at depth 2 moves by 0.25, layer at depth 3 moves by 0.125, etc.

Upvotes: 0

rptwsthi
rptwsthi

Reputation: 10172

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

create you cloud sprite:

CCSprite *blackCloud;//set it's 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)]];
    }
  }

Upvotes: 1

Related Questions