Okay, I've been going at this for hours and I am genuinely confused. My code for the Background class is below:
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)
}
}
What I also have right now are the following atlas files pointing to the png files inside them
background@2x~iphone.atlas --> background.png, background-567h.png, background-667h.png
background@3x~iphone.atlas --> background.png
background~ipad.atlas --> background.png
background@2x~ipad.atlas --> background.png
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.
I was originally following the solution for this post but I just don't understand what went wrong.
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.
EDIT - NOTE I am testing on iOS 7.03, 7.1 and 8.0
I've reduced my investigation to
background.atlas --> background.png (iPad 2)
background@2x.atlas --> background.png (iPhone 4s)
iPad 2 shows correct results, but, its texture is being used for the iPhone 4s.
If, I have the setup like this:
background@2x~iphone.atlas --> background.png (iPhone 4s)
background~ipad.atlas --> background.png (iPad 2)
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" '
For the above two, it seems the texture in the atlas that comes first is what is being used by default
If, I have the setup like this:
background.atlas --> background~ipad.png (iPad 2)
background@2x.atlas --> background@2x~iphone.png (iPhone 4s)
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
Another Edit
The last bullet point at the bottom of this page 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?
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.