What is the best way to aspect image fit the blue box? The game is pixel-based, so I would like to keep the pixellated look to it as well.
0
votes
2 Answers
0
votes
According with the actual Swift 2.2 you can find:
@available(iOS 7.0, *)
public enum SKSceneScaleMode : Int {
case Fill /* Scale the SKScene to fill the entire SKView. */
case 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. */
case 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. */
case ResizeFill /* Modify the SKScene's actual size to exactly match the SKView. */
}
You can do it for example in your viewController :
override func viewDidLoad() {
super.viewDidLoad()
if let scene = PreloadScene(fileNamed:"PreloadScene") {
// Configure the view.
let skView = self.view as! SKView
...
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFit
...
skView.presentScene(scene)
}
}
Or transiting from a SKScene
to another SKScene
:
let transition = SKTransition.doorsOpenVerticalWithDuration(0.5)
let nextScene = MainScene(size: self.scene!.size)
nextScene.scaleMode = .AspectFit
self.scene?.view?.presentScene(nextScene, transition: transition)