Search code examples
iosswiftsprite-kitscene

Size of scene does not fit to screen SpriteKit


I'm changing scene from one to other, and first scene is OK and fit to screen, but when I go to second scene, it doesn't fit to screen. Here's my code:

timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)

}


func update() {

    let transition = SKTransition.reveal(with: .down, duration: 1.0)

    let nextScene = GameScene(size: self.frame.size)
    nextScene.scaleMode = .aspectFill
    scene?.view?.presentScene(nextScene, transition: transition)

I try change scaleMode and size of GameScene, but without success. Thanks for any tips!


Solution

  • Hello I am using this code, so just try to change it a little bit:

            let nextScene = GameScene(fileNamed:"GameScene")
            nextScene!.scaleMode = .aspectFit
            let reveal = SKTransition.crossFade(withDuration: 1)
            self.view?.presentScene(nextScene!, transition: reveal)
    

    I think that the difference is using .aspectFit instead of .aspectFill.

    If it does not work just let me know :)