1

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!

enter image description here

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
        }
    }
Community
  • 1
  • 1
  • Remove the space in `Menu Scene` on the first "wrong" line. – ovejka Nov 24 '16 at 18:44
  • Did it , now I have a problem that says type MenuScene Has No Member unarchiveFromFile – Kate Yashenko Nov 24 '16 at 18:50
  • @ovejka I think that I have to put something else after MenuScene. Instead of unarchiveFromFile ? – Kate Yashenko Nov 24 '16 at 18:53
  • You probably don't have this method in your file. This should help: http://stackoverflow.com/a/27177083/3212863. Try to copy extension from the second answer between `import GameplayKit` and `class GameViewController: UIViewController` and make it compile, cause it can be other version of swift. – ovejka Nov 24 '16 at 19:03
  • Doesn't Work. But thank you anyway! – Kate Yashenko Nov 24 '16 at 19:08
  • How you going with this? I've just solved this with a LOT of help from two people here. But it's a bit weird how I blended different advice... and follows ZERO good practices. – Confused Nov 30 '16 at 21:50

0 Answers0