Pixel density
First of all the size of the Scene is defined in Points
not Pixels
.
Let's see how the devices that support iOS 9 deal with this:
- 1 point = 1x1 pixel: iPad 2, iPad mini
- 1 point = 2x2 pixels: iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6s, iPad mini 2, iPad mini 3, iPad mini 4, iPad 3,
iPad 4, iPad Air, iPad Air 2, iPad Pro, iPod touch 5, iPod touch 6
- 1 point = 3x3 pixels: iPhone 6 Plus, iPhone 6s Plus
This allow you to specify a size that is automatically converted for the pixel density of a particular device.
Screen size
There are several screen sizes available on the iPhone/iPad supported by iOS 9.
With SpriteKit you can easily face this problem setting the scaleMode
property of your Scene
.
You can chose among 4 options:
- Fill: Scale the SKScene to fill the entire SKView.
- AspectFill: Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a
different aspect ratio.
- AspectFit: Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if
the view has a different aspect ratio.
- ResizeFill: Modify the SKScene's actual size to exactly match the SKView.
You probably want to set AspectFill
but it really depends on your game.
To set the property open GameViewController.swift
(or .m
if you use Objective-C), in viewDidLoad
you'll find this line. Just change it to mach your preference.
/* Set the scale mode to scale to fit the window */
gameScene.scaleMode = .AspectFill