hi All,
I am working over a game in which i have a character associated with motions like move left/right on button press on screen.
I have implemented side scrolling in the game using :
CCSprite *bg=[CCSprite spriteWithFile:@"bg.JPG"];
CCSprite *bg1=[CCSprite spriteWithFile:@"bg1.jpg"];
CCSprite *bg2=[CCSprite spriteWithFile:@"bg2.jpg"];
CCSprite *bg3=[CCSprite spriteWithFile:@"bg3.jpg"];
bg.position=ccp(size.width/2,size.height/2);
bg1.position=ccp(size.width+480,size.height/2);
bg2.position=ccp(size.width+1440,size.height/2);
bg3.position=ccp(size.width+2400,size.height/2);
//add schedule to move backgrounds
[self schedule:@selector(scroll:)];
[self addChild:bg z:-1];
[self addChild:bg1 z:-1];
[self addChild:bg2 z:-1];
[self addChild:bg3 z:-1];
[spriteSheet addChild:_player z:0];
} return self;
}
- (void) scroll:(ccTime)dt {
self.position = ccp( self.position.x - 30*dt, self.position.y );
//reset position when they are off from view.
if (self.position.x < -2880) {
self.position = ccp(0, self.position.y);
}
}
This code works pretty well for me as it scrolls my background in a loop . However i have other sprites like player, buttons which are moving along with the background. I wish to stop them .
Main objective of mine is to make the backgrounds scroll only if player is move forward. If player moves x space, my background goes currentposition-x into left.
However i am not able to implement these issues. Need some help here. Thanks.
P.S. If someone wish to see the complete code of this *.m file please let me know.