swiftsprite-kitskscene

SKScene Viewable Size smaller than View bounds


I know my question is similar to SKScene view not filling screen but the answer there does not answer the issue I am having.

I want the screen to fill the entire screen and not just a sub-section of it. I am using the Game template from Xcode 12.4 and the image below is how the game runs on the iPhone 12 simulator. Additionally, the scene size is 750x1334.

enter image description here

When I change the size of the scene with scene.size = view.bounds.size I get the following:

enter image description here

The scene size changes as evidenced by the label being bigger but the viewable size is still the same. Is there a different size setting I should be changing? Im new to SpriteKit so any information would be helpful. Thanks!

Full GameViewController Code

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    
    if let view = self.view as! SKView? {
        // Load the SKScene from 'GameScene.sks'
        if let scene = SKScene(fileNamed: "GameScene") {
            scene.scaleMode = .aspectFill
            //Added below code in hopes to create larger viewable area
            //scene.size = view.bounds.size
            view.presentScene(scene)
        }
        
        view.ignoresSiblingOrder = true
        view.showsFPS = true
        view.showsNodeCount = true
    }
}

override var shouldAutorotate: Bool {
    return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    if UIDevice.current.userInterfaceIdiom == .phone {
        return .allButUpsideDown
    } else {
        return .all
    }
}

override var prefersStatusBarHidden: Bool {
    return true
}
}

Solution

  • I think this might be because Apple has mistakenly removed the launch screen from the iOS-only SpriteKit game template (it's still there in the multi-platform template). You need to either add and assign a launch screen or choose Main as your launch screen.

    The launch screen defines the working area for the app, so without it the view bounds and scene scale mode will not fix this issue.

    More info in Background is not filling the whole view SpriteKit.