SKScene size issue

Hello everyone, I am having an issue with Swift and I wanted to see if I can get some help. I am making a game using the phones accelerator that detects wether the phone is tilted in a certain direction. My problem is that my moveable block is moving out of the SKScene. I wanted to see if there was a way to size the SKScene to the phone. When I use the “fit” for the size on the SKScene, it creates black bars on the top and the bottom of the phone. Can someone help me get this corrected?

@PixelatedAngel

Welcome to the community.

I’ve created a few games as part of the 100 Days of Swift course from Paul Hudson that I followed some time back. They were a refreshing and fun exercise that he included in the course which I think everyone enjoyed who took that course. I certainly had a blast with them not that I have done anything since.

What settings do you have in GameScene.sks?

Have a look at the Size setting in the Attributes Inspector on the right hand side panel. You will need to configure that to suit the dimensions of the device you want the game to work on and/or consider the following.

Also in your GameViewController you might want to consider this boilerplate code that Paul used on each of the games he covered.

    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let view = self.view as! SKView? {
            // Load the SKScene from 'GameScene.sks'
            if let scene = SKScene(fileNamed: "GameScene") {
                // Set the scale mode to scale to fit the window
                scene.scaleMode = .aspectFit
                
                // Present the scene
                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
    }