Swift 2 SkScene 改变

Swift 2 SkScene Changing

我对编码 (swift) 和制作游戏都是新手。我正在尝试让我的游戏切换我创建的 SKScenes,出于某种原因,当我尝试切换场景时,我只是看到一个灰色屏幕,我不知道为什么。 (应该注意的是,我尝试转换的场景已经从之前的主场景改变了。下面是我用来改变场景的方法。(我不希望 SKScenes 之间有任何转换)

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches {
        let location = touch.locationInNode(self)

        if(self.nodeAtPoint(location).name != nil && self.nodeAtPoint(location).name != "enter") {
            userSequence.append(Int(self.nodeAtPoint(location).name!)!)
            print("userSequence:\(userSequence)")
        }
        if(self.nodeAtPoint(location).name == "enter"){
            //compareSequences()
            if PreviewNumbersGameScene.sharedInstance.TempGeneratedSequence == userSequence.reverse(){
                print(PreviewNumbersGameScene.sharedInstance.TempGeneratedSequence)
                print("good")
                let Winscene = WinGameScene(fileNamed: "WinGameScene")

                self.scene!.view?.presentScene(Winscene)
            }
            else{
                print("Temp:\(PreviewNumbersGameScene.sharedInstance.TempGeneratedSequence)")
                loose()
                print("bad")

            }

        }
    }
}

这是我要更改的场景:(名称是 WinGameScene

import SpriteKit

class WinGameScene: SKScene{


//MARK: - Variables




//MARK: - View
override func didMoveToView(view: SKView) {

    ///* Setup your scene here */

    loadView()
}


func loadView(){

    backgroundColor = SKColor.greenColor()
    print("winSceneLoaded")
}



override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    for touch in touches {

        let scene = PreviewNumbersGameScene(fileNamed: "PreviewNumbersGameScene")

        self.view?.presentScene(scene)
    }
}

}

为了转换到一个新的场景,你应该这样做:

if let winGameScene = WinGameScene(fileNamed: "WinGameScene") {

            self.view?.presentScene(winGameScene)
}else{
     print("error")
}

这里重要的是,在您尝试执行此操作之前,您必须创建一个名为 WinGameScene.sks 的资源文件。您可以通过以下方式执行此操作:File->New->File...->Resource->SpriteKit Scene。