title: Scrolling background - Sprite Kit
body: <p>So I tried to create an infinite scrolling background by using this post's solution (<a href="https://stackoverflow.com/questions/19349168/sprite-kit-side-scrolling">Sprite kit side scrolling</a>).
   However, I would want to make the image repeatable. As you can see in the video below, after the image has finished it's horizontal way, there is some empty gap.. I would like to make the image fill that gap, so repeat it endlessly.</p>
  
  <p><a href="http://www.youtube.com/watch?v=kyLTGz7Irrc" rel="nofollow noreferrer">http://www.youtube.com/watch?v=kyLTGz7Irrc</a>
  or
  <a href="https://vimeo.com/79555900" rel="nofollow noreferrer">https://vimeo.com/79555900</a> (password: spritekit)</p>
  
  <p>What I did : </p>
  
  <pre><code>for (int i = 0; i &lt; 2; i++) {
          SKSpriteNode * bg = [SKSpriteNode spriteNodeWithImageNamed:@"bgimage"];
          bg.anchorPoint = CGPointZero;
          bg.position = CGPointMake(CGRectGetMidX(self.frame), self.frame.origin.y);
          bg.name = @"snow1";
          [self addChild:bg];
   }
  </code></pre>
  
  <p>and in update method:</p>
  
  <pre><code>[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 &lt;= -bg.size.width)
              bg.position = CGPointMake(bg.position.x + bg.size.width * 2, bg.position.y);
      }];
  </code></pre>