0
votes

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.

enter image description here

2
...use the Aspect Fit scale mode? - Knight0fDragon
Do I call it on self.view? Will this scale all the nodes? - Latcie

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)
0
votes

you can scale your sprite fit to blue box.

func fitToBlueBox(node:SKSpriteNode, blueBox:SKSpriteNode) {
    let actualScale = min(blueBox.size.width/node.size.width, blueBox.size.height/node.size.height)
    node.setScale(actualScale);
}