I am unable to load my GameScene.sks file. I do not get any errors in either GameScene.swift or GameScene.sks
import UIKit
import SpriteKit
class GameViewController: UIViewController {
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 = .resizeFill
// Present the scene
view.presentScene(scene)
}
}
}
I managed to fix the problem. Below is the working code.
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = GameScene(fileNamed: "GameScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .resizeFill
The problem was that instead of specifying what scene I was suppose to load I had used the more generic SKScene
identifier
if let scene = SKScene(fileNamed: "GameScene")
The simple fix was changing the "SKScene" to my SKScene name.
if let scene = GameScene(fileNamed: "GameScene")
Hope this may be of help to anyone else experiencing this issue.