2

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:

.aspectFill

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:

.aspectFit

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

Robin
  • 373
  • 1
  • 3
  • 20
  • 1
    I am going to guess you are having difficulty understanding aspect ratio. IPads have 2 different aspect ratios, 139:199 and 3:4. To be able to manage both, you are going to have to accept that certain things are going to be cut off. What is your "Target" style, the 11" pro, or the regular Ipad – Knight0fDragon Sep 03 '19 at 13:27
  • 1
    @Knight0fDragon I aknowledge the aspect ratio problem and I don’t care about things getting cut off the screen (for now), I just want the entire screen filled up with the Game Scene. – Robin Sep 03 '19 at 14:11
  • 1
    You are going to have to elaborate more on where your problem is, or perhaps provide the code that is actually causing the problem. You are showing us your “menu” code where you need to be showing us your actual game code, and how you are presenting it. – Knight0fDragon Sep 03 '19 at 14:48
  • 1
    My second guess is going to be you have an skview inside an skview, and this is why you are seeing both your menu and your scene at the same time – Knight0fDragon Sep 03 '19 at 14:51
  • 1
    @Knight0fDragon I do have an SKView within another SKView. Why should this be a problem? On the iPhone simulators (yes, of all aspect ratios) the game scene covers the main menu. – Robin Sep 03 '19 at 19:38
  • You are not constraining you child SKView properly. I believe auto constraints may be kicking in when you just slap on a view, and since the simulator is a simulator and not an emulator, you are getting the different results. – Knight0fDragon Sep 03 '19 at 19:40
  • BTW, I strongly recommend against this. Having 2 SKView running is going to affect performance, so unless you are doing it visually show 2 different scenes at the exact same time, I would recommend sticking with 1 view that swaps out scenes. – Knight0fDragon Sep 03 '19 at 19:42

1 Answers1

2

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:

Original

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

Changed

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.

M. Black
  • 353
  • 1
  • 4
  • 20
Robin
  • 373
  • 1
  • 3
  • 20