Search code examples
iosswiftsprite-kitskspritenodeskscene

SpriteKit SKScene size for iPhone 5, 6 and 6 plus


I'm trying to build an app using SpriteKit for iPhone 5,6, and 6 plus. I have created a background image for each resolution:

image-1.png    // of size 1136 x 640, for iPhone 5
image-1@x2.png // of size 1334 x 750, for iPhone 6
image-1@x3.png // of size 2208 x 1242, for iPhone 6 plus

In Xcode 7, when I run my code on the simulator for iPhone 6 and 6 plus the correct and corresponding image is automatically picked. But when I run the code for iPhone 5 the iPhone 6 image is picked (image-1@x2.png) and not the correct image (image-1.png). Why?

In SKScene.didMoveToView() I set the scene size to the view's frame size:

self.size = view.frame.size

When I add the image to the scene I do:

self.addChild(SKSpriteNode(imageNamed:"image-1"))

If I use "image-1.png", I get the same result.


Solution

  • There is no such place specially for iPhone 5 and 6. they both take @2x images. So in both device it will pick @2x images.

    You need to set programmatically or on based condition.

    Refer to my old question : Images.xcassets taking wrong image for the iPhone 6?