title: How to organize Texture Atlas for Sprite-Kit
body: <p>Okay, I've been going at this for hours and I am genuinely confused. My code for the Background class is  below:</p>
  
  <pre><code>class Background : SKNode {
  
      required init(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      override init() {
          super.init()
          buildBackground()
      }
  
  
      func buildBackground() {
          var sprite : SKSpriteNode = SKSpriteNode(imageNamed: "background_full")
  
          sprite.anchorPoint = CGPointZero
          self.addChild(sprite)
      }
  
  }
  </code></pre>
  
  <p>What I also have right now are the following atlas files pointing to the png files inside them</p>
  
  <pre><code>background@2x~iphone.atlas --&gt; background.png, background-567h.png, background-667h.png
  background@3x~iphone.atlas --&gt; background.png
  background~ipad.atlas --&gt; background.png
  background@2x~ipad.atlas --&gt; background.png
  </code></pre>
  
  <p>I get unpredictable, irrational, random results where images may not have been found for the iPhone 4s at iOS 7 but is perfectly fine at iOS 8 (however makes use of the image meant for the iPhone 5). And the iPhone 5 will use the texture for the iPad @1x and so on.</p>
  
  <p>I was originally following
  <a href="https://stackoverflow.com/questions/20889581/how-to-make-sprite-kit-display-2x-images-from-atlas-at-correct-size">the solution for this post</a> but I just don't understand what went wrong.</p>
  
  <p>Note: @3x gives me an error, but I understand why, the file is too large to be contained in an atlas and I plan to divide the background after I get the basics to work. So you can ignore @3x as I haven't included it in my project, I just thought I give you the full picture.</p>
  
  <h2>EDIT - NOTE I am testing on iOS 7.03, 7.1 and 8.0</h2>
  
  <p>I've reduced my investigation to</p>
  
  <pre><code>background.atlas --&gt; background.png (iPad 2)
  background@2x.atlas --&gt; background.png (iPhone 4s)
  </code></pre>
  
  <p>iPad 2 shows correct results, but, its texture is being used for the iPhone 4s.</p>
  
  <p>If, I have the setup like this:</p>
  
  <pre><code>background@2x~iphone.atlas --&gt; background.png (iPhone 4s)
  background~ipad.atlas --&gt; background.png (iPad 2)
  </code></pre>
  
  <p>iPhone 4s shows correct results, but, its texture is being used for the iPad 2 and for both devices I get an error at iOS 8.0 showing the path to app in the Simulator devices saying 'SKTexture couldn't load image resource ".../background@2x~iphone.atlasc/background@2x~iphone.1.png" '</p>
  
  <p>For the above two, it seems the texture in the atlas that comes first is what is being used by default</p>
  
  <p>If, I have the setup like this:</p>
  
  <pre><code>background.atlas --&gt; background~ipad.png (iPad 2)
  background@2x.atlas --&gt; background@2x~iphone.png (iPhone 4s)
  </code></pre>
  
  <p>then everything works, except at iOS 7.03 where I get an error saying 'SKTexture couldn't load image resource "background.png" ' and that's it, no long path like in the previous example</p>
  
  <h2>Another Edit</h2>
  
  <p>The last bullet point at the <a href="https://developer.apple.com/library/ios/recipes/xcode_help-texture_atlas/AboutTextureAtlases/AboutTextureAtlases.html" rel="nofollow noreferrer">bottom of this page</a> reveals to me that if I bunch together all my background PNG files from all devices into one atlas, SpriteKit will separate into appropriate devices, so the right textures will be loaded into memory. But, then I would have to differentiate between all the iPhone models (in particular iphone 5 and 6 which are declared at @2x). Am I right to say that the relevant PNG files for a device will be loaded if I bunch them all together?</p>
  
  <p>If not, I've decided to separate the PNGs into their own device atlas and write a bit of code that differentiates and loads the correct atlas.</p>