Search code examples
sprite-kitswift2skscene

Switching Scenes in SpriteKit Swift 2


I have been trying to make a game in sprite kit and I want to implement a start screen with a play button that takes you to the actual game. I have seen many ways to do it but most of them use swift 1 and are not up to date Here is the code to my function

func switchScene()
{
    let scene = GameScene(fileNamed: "PlayScene")
    let transition = SKTranstion.crossFadeWithDuration(1)
    self?.view.presentScene(scene, transition)
}

where PlayScene is a swift class that extends SKScene


Solution

  • In my games, I use this:

    // Setting a size (or else it may look like its zoomed in)
    var selectView = BallSelect(size: view!.bounds.size) 
    // Setting a file for that scene
    selectView = BallSelect(fileNamed: "BallSelect")! 
    // Setting the scale
    selectView.scaleMode = SKSceneScaleMode.AspectFill 
    // Transitioning scenes wit a specific transition
    self.scene?.view?.presentScene(selectView, transition: SKTransition.fadeWithColor(color, duration: 1)) 
    

    Tell me if it works :)