我使用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()
}
}
}
答案 0 :(得分:1)
你只需制作一个新的场景(和转换,但这是可选的)并使用适当的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)
}
如果没有转换,您只需使用presentScene方法而不是presentScene:transition