Swift - Overlaying a SKScene onto a UIView - Grey Background

Viewed 567

I'm new to Swift and Xcode and am just playing around with SpriteKit. What I did is that I created a UIView in main.storyboard. The UIView (named overlayedGameScene) is only taking up about half of the screen, so you should be able to see the main UIView (self.view).

import UIKit
import SpriteKit
import GameplayKit

class GameViewController: UIViewController {
    @IBOutlet var overlayedGameScene: SKView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.blue
        self.view.alpha = 1

        if let theView = overlayedGameScene as SKView? {
            if let theScene = SKScene(fileNamed: "GameScene.sks") {
                theScene.scaleMode = .aspectFill

                theView.presentScene(theScene)
            }
        }
    }
}

It worked fine, but the only problem was that when I ran it in the simulator, the main view was grey when I had changed it to blue both in the storyboard and programmatically. I also changed the alpha both in the storyboard and programmatically.

This is what it looks like in the simulator.

Should I just add another blue UIView over the main view? Is there a reason for why this is happening.

1 Answers
Related