user3593148
user3593148

Reputation: 505

how to transition scenes with swift in spritekit

Having some trouble figuring out what i need to add to the below code in order to switch scenes when a node is touched. What do i need to replace the '....' with in order to have the code below it run.

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)
    }
}

Upvotes: 0

Views: 429

Answers (1)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71852

You can use this code :

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)
        }
    }
}

Upvotes: 4

Related Questions