0

I am making a game using SpriteKit, and I want it to use the whole screen. However, right now, it is only using what looks to be the safe area. How can I make the view take up the entire screen? Below is the GameViewController code I am using:

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        if let view = self.view as! SKView? {
            // Load the SKScene from 'GameScene.sks'
            let scene = MenuScene(size: UIScreen.main.bounds.size)
            // Set the scale mode to scale to fit the window
            scene.scaleMode = .fill
            // Present the scene
            view.presentScene(scene)
            view.ignoresSiblingOrder = true
            view.showsFPS = false
            view.showsNodeCount = false
        }
    }
}
helloworld12345
  • 139
  • 1
  • 12

1 Answers1

0

If you use SwiftUI, you can present your scene as a view using SpriteView. Then, you can apply the view modifier .ignoresSafeArea() to make it take up the whole screen.

Anyway, I'm a newbie, but that's what I did and it worked for me. There may be a better way, though.

Here's an example of what I'm talking about:

import SwiftUI
import SpriteKit

struct ContentView: View {
    var body: some View {
        SpriteView(scene: MenuScene(size: UIScreen.main.bounds.size), transition: SKTransition.reveal(with: .down, duration: 1.0))
            .ignoresSafeArea()
    }
}
West1
  • 374
  • 3
  • 14