I’ve been working on SpriteKit in XCode and have finally determined the best way to use the Universal asset files on each device.
In the fantastic game tutorials from Ray Wenderlich’s site recommends 2048 x 1536, with all background images set to the same size. But I wanted to make sure to optimize each of the images with the new Universal asset size collection.
This new asset size allows for 1x – 3x images and are the type that the default app uses when creating a Swift SpriteKit game.
For the asset sizes for your background images (in landscape mode)
- 1x: 1024 x 768
- 2x: 2048 x 1536
- 3x: 3072 x 2304
Most of the different platforms will use the 2x resolution. But the iPad 2 uses the 1x, and the iPhone 6 uses the 3x.
- iPhone 4: 2x
- iPhone 5: 2x
- iPhone 5s: 2x
- iPhone 6: 2x
- iPhone 6s: 3x
- iPad 2: 1x
- iPad Air: 2x
- iPad Retina: 2x
In my GameViewController, I hard code my GameScene to 1024×768.
class GameViewController : UIViewController{ override func viewDidLoad(){ super.viewDidLoad() let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true skView.ignoresSiblingOrder = true let scene = GameScene(size: CGSize(width: 1024, height: 768)) scene.scaleMode = .AspectFill skView.presentScene(scene) }
Then in the Game Scene, to present your background image
class GameScene : SKScene{ let background : SKSpriteNode = SKSpriteNode(imageNamed: "background") override func didMoveToView(view: SKView){ background.position = CGPoint(x: size.width / 2, y: size.height / 2) addChild(background) } }