Issues with SKScene on iPad simulator not filling screen in Xcode 11 beta 7

大兔子大兔子 提交于 2020-05-30 07:05:44

问题


In Xcode 11 beta 7, I am having issues with my SKScene, my GameScene does not fill the entire screen of the iPad simulator. This is true for all iPad simulators. On my physical iPad the Game Scene is as intended, but I worry this may not be true of all iPad's. On all iPhone simulators and on my iPhone, the Game Scene is also displayed as intended.

I have two SKScenes, one is the Main Menu screen which fills the entire screen, but my Game Scene does not, when I load the Game Scene it is square and the Main Menu screen is visible underneath, like so:

The following is the code for my GameViewController, which is practically identical to my MainMenuViewController except all instances of "Game" are "MainMenu":

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Load 'GameScene.sks' as a GKScene. This provides gameplay related content
        // including entities and graphs.
        if let scene = GKScene(fileNamed: "GameScene") {

            // Get the SKScene from the loaded GKScene
            if let sceneNode = scene.rootNode as! GameScene? {

                // Copy gameplay related content over to the scene
                sceneNode.entities = scene.entities
                sceneNode.graphs = scene.graphs

                // Set the scale mode to scale to fit the window
                sceneNode.scaleMode = .aspectFill

                // Present the scene
                if let view = self.view as! SKView? {
                    view.presentScene(sceneNode)

                    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
    }
}

I have tried changing the line sceneNode.scaleMode = .aspectFill to sceneNode.scaleMode = .aspectFit, but that produces the following:

So, how do I make my Game Scene, the red area, fill the entire iPad's screen?


回答1:


Typical that after setting a bounty I find the answer.

The issue was in my storyboard file, not my code:

Originally, I had this in the properties of my view after the segue:

And changing it to this made the SKView fill the entire screen:

Clearly at some point Xcode changed so that 'Automatic' no longer filled the screen for whatever reason.

Edit: For more clarification, when you open the storyboard file, click/select the view controller that you want to adjust, under the Attributes Inspector, there is an option for Presentation where you can select the "Full Screen" attribute.



来源:https://stackoverflow.com/questions/57771341/issues-with-skscene-on-ipad-simulator-not-filling-screen-in-xcode-11-beta-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!