Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用LabelNode在精灵套件(Swift)中的场景之间切换_Swift_Sprite Kit_Skscene - Fatal编程技术网

使用LabelNode在精灵套件(Swift)中的场景之间切换

使用LabelNode在精灵套件(Swift)中的场景之间切换,swift,sprite-kit,skscene,Swift,Sprite Kit,Skscene,我使用SKLabelNodes作为按钮,在菜单助手中使用if来检测对它们的触摸。打印是可行的(检测也是如此),但如何正确切换到游戏场景 func menuHelper(touches: NSSet) { for touch in touches { let nodeAtTouch = self.nodeAtPoint(touch.locationInNode(self)) if nodeAtTouch.name == "title"

我使用
SKLabelNodes
作为按钮,在菜单助手中使用
if
来检测对它们的触摸。打印是可行的(检测也是如此),但如何正确切换到游戏场景

func menuHelper(touches: NSSet) {
        for touch in touches {
            let nodeAtTouch = self.nodeAtPoint(touch.locationInNode(self))
            if nodeAtTouch.name == "title" {
                print("Title pressed")
            }
            else if nodeAtTouch.name == "newGame" {
            let scene = GameScene()
            }
        }

}

您只需创建一个新场景(和过渡,但这是可选的),并使用适当的SKView方法呈现:

else if nodeAtTouch.name == "newGame" {

   let transition = SKTransition.fadeWithDuration(1.0)

   let nextScene = GameScene(size: scene!.size)
   nextScene.scaleMode = .AspectFill //set the scale mode like you did in your view controller

   scene?.view?.presentScene(nextScene, transition: transition)
}

如果没有转换,您将只使用方法,而不是

它可以工作,谢谢。但我还是不太确定你的和我的有什么区别。这基本上是你的最后一行吗?@FelixF是的,这是最重要的部分。另外,我已经用旧场景的大小初始化了新场景的大小,并设置了缩放模式。所以,正如我所说的,重要的一点是,你必须呈现新的场景来取代当前的场景。仅创建新场景不会自动完成此操作。希望这有意义!谢谢,现在完全有道理了!:)