title: Swift Background Image Dropping FPS / Texture Change Causing Lag
body: <p>I'm building my first game in Swift so please go easy... I've put together a game that runs pretty well, when I add a background image to my GameScene, it basically drops the FPS by 30-40%. The background image is 225KB.</p>
  
  <p>I've added the following to didMoveToView:</p>
  
  <pre><code>var background = SKSpriteNode(imageNamed: "bg");
  background.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2)
  background.size = self.frame.size
  self.scaleMode = SKSceneScaleMode.ResizeFill
  self.addChild(background)
  </code></pre>
  
  <p>In <code>touchesEnded</code></p>
  
  <p>On each click I'm changing the texture like so:</p>
  
  <pre><code>projectile.texture = SKTexture(imageNamed: "rabbit")
  </code></pre>
  
  <p>Is this the right way to change each time there's a click?</p>
  
  <p>The reason I've set the background here is because every time I set the background in the GameViewController, it covers my GameScene and I've tried using z-index and sending the background to the back but I had no luck after 1-2 hours of trying.</p>
  
  <p>I have a strong feeling this is what is dropping my FPS because it's another SKSpriteNode - even when I start up the game it lags.</p>
  
  <p>Is there a way in instruments to see what line of code or block of code is causing the lag?</p>
  
  <p>Is there a better way to assign this background to reduce lag? I'm using around 15 small images and each 10 seconds I'm switching a texture--could that be why? I also feel that switching a texture each 10 seconds could be causing this.</p>
  
  <p>Any advice is greatly appreciated.</p>