从GameOverScene过渡到GameScene

时间:2016-02-03 01:20:21

标签: ios swift sprite-kit

我试图从我的GameOverScene过渡回我的GameScene。我有以下触摸功能,但当我按下“重播游戏”时按钮它没有过渡。

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

    let touch = touches.first! as UITouch
    let touchLocation = touch.locationInNode(self)
    let touchedNode = self.nodeAtPoint(touchLocation)

    if let name = touchedNode.name {
        if name == "replay"{
            print("Touching Replay")
            let reveal : SKTransition = SKTransition.flipHorizontalWithDuration(0.5)
            let scene = GameScene(size: self.size)
            scene.scaleMode = .AspectFill
            self.view?.presentScene(scene, transition: reveal)
        }
    }
}

我还有以下用于创建我的重播节点:

let replayMessage = "Replay Game"
var replayButton = SKLabelNode(fontNamed: "Chalkduster")
replayButton.text = replayMessage
replayButton.fontColor = SKColor.blackColor()
replayButton.position = CGPointMake(self.size.width/2, 50)
replayButton.name = "replay"
self.addChild(replayButton)

我得到以下输出:

  

触摸重播2016-02-03 01:11:08.102测试[1010:196002] CUICatalog:   无效请求:请求子类型而不指定习语

1 个答案:

答案 0 :(得分:1)

嗨,试试这个:

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

        let touch = touches.first! as UITouch
        let touchLocation = touch.locationInNode(self)
        let touchedNode = self.nodeAtPoint(touchLocation)

        if let name = touchedNode.name {
            if name == "replay"{
            let transition = SKTransition.fadeWithColor(UIColor.whiteColor(), duration:1.0)
            let GameOver = MainScene(size: scene!.size)
            GameOver.scaleMode = scaleMode
            view!.presentScene(GameOver, transition: transition)
            print("Game Over!")
            }
        }
    }