I have a method that has a custom segue in my viewController that looks like this:
func gameOver() {
performSegueWithIdentifier(\"GameOver\", sender: nil
I have done by create protocol, I have 3 game scene (GameScene, GamePlayScene, GameEndScene) and one game controller (GameViewController)
first create gameProtocol
protocol GameDelegate {
func gameOver()
}
implement protocol in GameViewController
class GameViewController: UIViewController, GameDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
scene.delegate = self
}
// MARK: Game Delegate
func gameOver() {
self.performSegueWithIdentifier("yoursegue", sender: self)
}
}
put delegate property in GameScene class
class GameScene: SKScene {
var delegate: GameDelegate?
// call GamePlayScene and put delegate property
func redirectToPlay() {
let transition = SKTransition.pushWithDirection(SKTransitionDirection.Left, duration: 1.0)
let menuScene = GamePlayScene(size: size)
menuScene.delegate = self.delegate
self.view?.presentScene(menuScene, transition: transition)
}
}
and put protocol in GamePlayScene too
class GamePlayScene: SKScene {
var delegate: GameDelegate?
// call GameEndScene and put delegate property
func gameScore() {
let transition = SKTransition.pushWithDirection(SKTransitionDirection.Left, duration: 1.0)
let menuScene = GameEndScene(size: size)
menuScene.delegate = self.delegate
self.view?.presentScene(menuScene, transition: transition)
}
}
and last, put delegate property and call gameOver function
class GameEndScene: SKScene {
var delegate: GameDelegate?
init(size: CGSize) {
// call gameOver function
self.delegate?.gameOver()
}
}
Hope that work and can help you
Sincerely, Donny