How to organize a texture atlas for Sprite-Kit

Okay, I've been going on this for hours and I'm really 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)
    }

}

      

I also have the following atlas files pointing to 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 am getting unpredictable, irrational random results where images may not have been found for iPhone 4s in iOS 7, but works great for iOS 8 (however uses an image designed for iPhone 5). And the iPhone 5 will use the texture for the iPad @ 1x, etc.

I originally followed the solution for this post , but I just don't understand what went wrong.

Note: @ 3x is giving me an error, but I understand why the file is too big to be included in the atlas and I plan to split the background after I get the basics to work with. So you can ignore @ 3x as I didn't include it in my project, I just thought I was giving you the full picture.

EDIT - NOTE. I am testing iOS 7.03, 7.1 and 8.0

I have reduced my research to

background.atlas --> background.png (iPad 2)
background@2x.atlas --> background.png (iPhone 4s)

      

iPad 2 shows correct results, but its texture is used for iPhone 4s.

If I have a 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 used for iPad 2 and for both devices I get an error in iOS 8.0 showing the app path on Simulator devices saying "SKTexture could not load image resource" ... / background @ 2x ~ iphone.atlasc / background @ 2x ~ iphone.1.png "'

For the two above, it seems that the texture in the atlas that comes first is the default

If I have a setup like this:

background.atlas --> background~ipad.png (iPad 2)
background@2x.atlas --> background@2x~iphone.png (iPhone 4s)

      

then everything works except iOS 7.03 where I get the error: "SKTexture could not load the image resource" background.png "and that it does not have a long path like in the previous example

Other editing

The last bullet point at the bottom of this page shows me that if I collect all my PNG files from all devices into one atlas, SpriteKit will split across the appropriate devices, so the correct textures will be loaded into memory. But then I would have to distinguish between all iPhone models (in particular the iphone 5 and 6, which are announced at @ 2x). Can I say that the corresponding PNG files for the device will be downloaded if I put them all together?

If not, I decided to split the PNGs into my own device atlas and write some code that distinguishes and loads the correct atlas.

+3


source to share


1 answer


Create one .atlas folder, then add all images to that folder, be sure to use correct naming convention like

rocky~ipad.png
rocky@2x~ipad.png
rocky@2x~iphone.png
drago~ipad.png
drago@2x~ipad.png
drago@2x~iphone.png

      

then add this folder.atlas file to your project and build xcode.

find the .app package in the products folder in xcode and right click in the search box, then right click on the set and select the package contents displayed, there you will find the .atlasc folder and inside folder.1~ipad.png

, folder.1@2x~ipad.png

and folder.1@2x~iphone.png

, each atlas with the corresponding dimensions and one. plist file with links to them.



also note that the ".1" in the atlas file should count the atlases, because when the images are larger than the allowed atlas size, xcode will make more atlases and count them with this convention.

worry not for the big game.

if necessary check this link

thanks.

      

+1


source







All Articles