making CCParallaxNode infinite, positioning the image
Hello I am making a cocos2d side scroller. I am using a CCParallaxNode for
the background. I have code that sets the initial position of the image.
How can I make it as a continuous scrolling CCParallaxNode??
In the init method:
backgroundNode = [CCParallaxNode node];
[self addChild:backgroundNode z:-5];
treeBackground = [CCSprite
spriteWithFile:@"thechangedbackgroundcopy.png"];
CGPoint backgroundSpeed = ccp(0.5, 0.5);
[backgroundNode addChild:treeBackground z:-5
parallaxRatio:backgroundSpeed positionOffset:ccp(screenWidth/2,
screenHeight/2 - 50)];
[self scheduleUpdate];
In the scheduleUpdate method:
-(void)update:(ccTime)delta{
CGPoint backgroundScrollVelocity = ccp(-150, 0);
backgroundNode.position = ccpAdd(backgroundNode.position,
ccpMult(backgroundScrollVelocity, delta));
}
No comments:
Post a Comment