So I tried to create an infinite scrolling background by using this post\'s solution (Sprite kit side scrolling). However, I would want to make the image repeatable. As you
The original logic that has a for loop works fine with minor changes:
for (int i = 0; i < 2; i++) {
SKSpriteNode * bg = [SKSpriteNode spriteNodeWithImageNamed:@"bgimage"];
bg.anchorPoint = CGPointZero;
bg.position = CGPointMake(i*bg.size.width, 0);
bg.name = @"snow1";
[self addChild:bg];
}
And in the update method:
[self enumerateChildNodesWithName:@"snow1" usingBlock: ^(SKNode *node, BOOL *stop) {
SKSpriteNode *bg = (SKSpriteNode *) node;
bg.position = CGPointMake(bg.position.x - 5, bg.position.y);
if (bg.position.x <= -bg.size.width) {
bg.position = CGPointMake(bg.position.x + bg.size.width * 2, bg.position.y);
}
}];