Reputation: 81
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.
I've reduced my investigation to
background.atlas --> background.png (iPad 2)
[email protected] --> 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)
[email protected] --> 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
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.
Upvotes: 3
Views: 2228
Reputation: 6417
Create one folder.atlas then add all the images into that folder, be sure to use correct naming convention, for example
rocky~ipad.png
rocky@2x~ipad.png
rocky@2x~iphone.png
drago~ipad.png
drago@2x~ipad.png
drago@2x~iphone.png
then,add that folder.atlas to your project, and do a xcode build.
search for the .app bundle in the products folder in xcode, and with right click choose show in finder, then right click over the bundle and choose show contents of the package, there you will find folder.atlasc and inside folder.1~ipad.png
, folder.1@2x~ipad.png
and folder.1@2x~iphone.png
, each atlas with the corresponding sizes and one .plist file with the references to them.
also please do note that the ".1" in the atlas file is to count atlases, since when images are bigger than atlas allowed size, xcode will make more atlases and count them with that convention.
worry non for biggerness.
if needed check this link
thanks.
Upvotes: 1