Reputation: 741
How to create an infinite background in cocos2d without block Gap.I am building an app with a ball moving from left to right, and I want it to move infinitely. Well in that case I would have an endless background so the ball could keep moving.I got gab between the image .I've continuously searched on this matter and have found nothing that actually works.
I have added code below
-(void)scroll:(ccTime )time
{
tree1.position = ccp(tree1.position.x-1, tree1.position.y);
tree2.position = ccp(tree2.position.x-1, tree2.position.y);
if (tree1.position.x<-tree1.boundingBox.size.width) {
tree1.position = ccp(tree2.position.x +tree2.boundingBox.size.width, tree1.position.y);
}
if (tree2.position.x<-tree2.boundingBox.size.width) {
tree2.position = ccp(tree1.position.x + tree2.boundingBox.size.width, tree1.position.y);
}
}
Upvotes: 2
Views: 303
Reputation: 1166
If the gap occurs between the sprites you are sliding to create the endless scrolling, the simplest common solution is overlapping your background stripes by 1 pixel.
In your image it appears that the gap appears when you are moving an sprite from the left to the right. Have you moved the anchor point of your sprites? so now they are left aligned?
Upvotes: 1