如何在spritekit中使用swift过渡场景

时间:2015-06-01 07:15:43

标签: ios swift sprite-kit

找出我需要添加到下面的代码中以便在触摸节点时切换场景时遇到一些麻烦。我需要更换'....'以便让它下面的代码运行。

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

    ....


    if touchedNode.name == "Game Button" {
        let transition = SKTransition.revealWithDirection(SKTransitionDirection.Down, duration: 1.0)

        let scene = File(size: self.scene.size)
        scene.scaleMode = SKSceneScaleMode.AspectFill

        self.scene.view.presentScene(scene, transition: transition)
    }
}

1 个答案:

答案 0 :(得分:4)

您可以使用此代码:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch in (touches as! Set<UITouch>) {

        let location = touch.locationInNode(self)

        if self.nodeAtPoint(location) == self.playButton {

            let reveal = SKTransition.flipHorizontalWithDuration(0.5)
            let letsPlay = playScene(size: self.size)
            self.view?.presentScene(letsPlay, transition: reveal)
        }
    }
}