Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am newbie programmer in cocos2D.... I wanted to create the Endless Background using the Parallax Scrolling.. I am trying to learn the Parallax but it doesn't update with the time and sprites doesn't keep on rotating from top to bottom! The snippet i tried is as below

-(id) init 
{
    if((self = [super init])) 
    {        
        CGSize wSize = [CCDirector sharedDirector].winSize;
        self.isTouchEnabled = YES;
        CGPoint topOffset = CGPointMake(wSize.width, 0); 
        CGPoint midOffset = CGPointMake(wSize.width/2,0);
        CGPoint downOffset = CGPointZero;        
        CCSprite *para1 = [CCSprite spriteWithFile:@"Default.png"];
        CCSprite *para2 = [CCSprite spriteWithFile:@"Icon.png"];
        CCSprite *para3 = [CCSprite spriteWithFile:@"Default.png"];
        CCSprite *para4 = [CCSprite spriteWithFile:@"Icon.png"];

        paraNode = [CCParallaxNode node];
        [paraNode addChild:para1 z:1 parallaxRatio:CGPointMake(0.5f, 0)
        positionOffset:topOffset];
        [paraNode addChild:para2 z:2 parallaxRatio:CGPointMake(1, 0) positionOffset:topOffset];
        [paraNode addChild:para3 z:4 parallaxRatio:CGPointMake(2, 0) positionOffset:midOffset];
        [paraNode addChild:para4 z:3 parallaxRatio:CGPointMake(3, 0) positionOffset:downOffset];
        [self addChild:paraNode z:0 ];
        [self scheduleUpdate];
     }
     return self;
}

-(void) update : (ccTime) dt
{   
//Need to move the Parallax Node with the repetition of the background
}

This is the Implementation file... I am stuck here for moving the contiunous moving of the background in the Horizontal or Portrait mode.

Thanks for the Help in Advance

share|improve this question
up vote 2 down vote accepted

CCParallaxNode doesn't support endless scrolling, unless you modify its code. I have an example for endless parallax scrolling in my Learn Cocos2D book. From that link you can also download the book's source code where you'll find the parallax class in chapters 6 to 8.

share|improve this answer
1  
okies.... thanks... – Marine Dec 10 '11 at 6:38

I have created a simple class named ParallaxManager which is capable for creating infinite parallax effect for both small sprite like small cloud

enter image description here

as well large layer sprite like grass. enter image description here

You can find out the complete project from GitHub.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.