I am following this question How to create a main menu for a spritekit game made with swift in xcode? step by step.
I have created one SKScene and one Cocoa Touch Class and in Cocoa Touch Class I inserted this :
import SpriteKit
class MenuScene: SKScene {
var playButton = SKSpriteNode()
let playButtonTex = SKTexture(imageNamed: "play")
override func didMove(to view: SKView) {
playButton = SKSpriteNode(texture: playButtonTex)
playButton.position = CGPoint(x: frame.midX, y: frame.midY)
self.addChild(playButton)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let pos = touch.location(in: self)
let node = self.atPoint(pos)
if node == playButton {
if let view = view {
let transition:SKTransition = SKTransition.fade(withDuration: 1)
let scene:SKScene = GameScene(size: self.size)
self.view?.presentScene(scene, transition: transition)
}
}
}
}
}
Now in GameViewController File I am trying to change from if let scene = GameScene.unarchiveFromFile("GameScene") as?
to if let scene = MenuScene.unarchiveFromFile("MenuScene") as? Menu Scene
.
However I keep getting this error. Please Help!
Here Is my code
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = GameScene.level(levelNum: 18) {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the sc ene
view.presentScene(scene)
// view.showsPhysics = true
}
view.ignoresSiblingOrder = false
view.showsFPS = true
view.showsNodeCount = true
}
}