Nexus S.
Nexus S.

Reputation: 145

Segues between gameScene.sks

I'm beginner in Swift and SpriteKit. I have gameViewController with code:

if let scene = IntroScene(fileNamed:"IntroScene") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true
        skView.ignoresSiblingOrder = true
        scene.scaleMode = .AspectFill
        skView.presentScene(scene)
    }
}

My app starting with this scene. I have some code with simple animation for this scene in other viewController:

let introAnimationFadeIn = SKAction.fadeInWithDuration(0.05)
let introAnimation = SKAction.animateWithTextures([introAnimation1, introAnimation2, introAnimation3, introAnimation4, introAnimation5], timePerFrame: 1.5)
let sequenceIntroAnimation = SKAction.sequence([
        introAnimationFadeIn,
        introAnimation])
intro.runAction(sequenceIntroAnimation)
  1. How I can create segue to other GameScene after animation complete?
  2. I want to create main menu in my project. Can I create segue to other GameScene, when SKSpriteNode touched? Or create button would be better? I know that segue can be only with viewControllers, but I don't know how names segues between game scenes correct. And sorry for my English.

Upvotes: 1

Views: 101

Answers (1)

Sweeper
Sweeper

Reputation: 274835

If you want to go from one scene to another, you don't use segues. Segues are transitions between view controllers, not SKScenes.

To present another scene, just get an SKView and call presentScene!

let scene = YourSceneClass(fileNamed:"Name of your scene that is going to present")!
view.presentScene(scene) // view is an SKView

And it seems like you want to do an animation before presenting the scene. You don't need SKActions for this. Why not use SKTransition instead?

You can use this code to transition to another scene with fade:

// again, view is an SKView
view.presentScene(scene, transition: SKTransition.fadeWithDuration(1))

Easy as that!

Upvotes: 3

Related Questions